Trigger recalculation after customfield is changed



Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/37a95255-0c6c-4e07-b4ff-237520a82815%40googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
Use prefix "custom_"  with the fieldname to call the trigger, it should work.

cur_frm.cscript.custom_amount_allocated_on_permit = function() {

    cur_frm.set_value("total_amount_lawfully_used", 999);

}

On 18-Feb-2014, at 1:21 PM, Robert Becht wrote:



Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.





Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/37a95255-0c6c-4e07-b4ff-237520a82815%40googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/F1C6E346-B7FC-4714-87F8-CE6B22EB5558%40gmail.com.

    For more options, visit https://groups.google.com/groups/opt_out.


Hi,

We are somehow stuck with something that seems relatively easy.

Say we have 3 custom fields: AAA, BBB, and CCC, where CCC=AAA*BBB

We fail to trigger the recalculation if the user changes AAA or BBB

Robert

Description of Bas below:


The following is what we try to achieve.
The two numbers circled with red are multiplied in order to get the number in green.
This works when the form loads (the 90 and the 7 are nicely fetched from elsewhere, and the 630 is computed).
When the user changes the 90 to e.g. 100, we wish the 630 to be recomputed. As this computation is "lightweight" (it is only a simple multiplication), the nicest is to have this as the user types. In the worst case, the recomputation can be done when the user leaves the "Amount Allocated on Permit" text field by clicking on another field.
Note that the number recomputes if the user first clicks the "close" arrow ( ^ ) and then re-selects the item to re-open it. But this is not good enough because it causes misunderstandings as to which numbers are actually used when creating the invoice. We want it to be interactive, recomputing this simple multiplication on-the-fly, preferrably as the user types.
We have just tried the _custom option, but that also doesn't have the effect, the number 630 stays as-is.

Thank you in advance for your kind support.





On 18/2/2014 14:04, Becht, R. (Robert, ITC) wrote:

u5:p</u5:p>

Nabin Hait 

https://groups.google.com/forum/clear.cache.gif

10:52 AM (3 hours ago)

Use prefix "custom_"  with the fieldname to call the trigger, it should work.

 

cur_frm.cscript.custom_amount_allocated_on_permit = function() {

u5:p</u5:p>

    cur_frm.set_value("total_amount_lawfully_used", 999);

u5:p</u5:p>

}

u5:p</u5:p>

- show quoted text -

 


On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/286895f9-3b31-4395-b262-98b64ee35133%40googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
the screen shot that did not get thru::



On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6591d0c2-f9c6-44af-b640-dbcc7bf777fd%40googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
You can define a common function for this:


function on_change_aaa_bbb(doc, cdt, cdn){


}


2014-02-18 11:07 GMT-03:00 Robert Becht <be…@gmail.com>:

the screen shot that did not get thru::



On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works)

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to
a form element like a text input field?

In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers)
I have found that one can add general form triggers for
"refresh", "onload" and "setup", e.g.
"cur_frm.cscript.refresh = function()". However I need an
"onchange" trigger for a specific text input field, as described
here: http://www.w3schools.com/jsref/event_onchange.asp



I tried the following:

cur_frm.cscript.amount_allocated_on_permit.onchange = function() {

cur_frm.set_value("total_amount_lawfully_used",
999);

refresh_field("total_amount_lawfully_used");

}

but nothing happens, the onchange isn't added to the "amount_allocated_on_permit"
text field.



I need this, because I want to recompute parts of the form when the user
changes some elements. I am trying to avoid adding a "recompute"
button, because that spoils the user's interactive experience. Therefore I need
a trigger that is called when the user made some changes in the form input.



Thank you,


Reply via mail:

For onchange trigger you should write the function with a little chnage:

cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




Note:



If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.



    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6591d0c2-f9c6-44af-b640-dbcc7bf777fd%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3
+55 11 954329659




Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CABK1YkM5J6tKt4a9G1i-F0vQeMbF7eE5wvHewWgfA4aSbm5OVw%40mail.gmail.com.

    For more options, visit https://groups.google.com/groups/opt_out.
Sorry, the last response is wrong!

function on_change_aaa_bbb(doc, cdt, cdn){
if (doc.aaa && doc.bbb){
doc.ccc = doc.aaa*doc.bbb;
cur_frm.refresh()
}
}

cur_frm.custom_aaa = on_change_aaa_bbb;

cur_frm.custom_bbb = on_change_aaa_bbb;



2014-02-18 11:09 GMT-03:00 Maxwell Morais <ma…@gmail.com>:

You can define a common function for this:


function on_change_aaa_bbb(doc, cdt, cdn){


}


2014-02-18 11:07 GMT-03:00 Robert Becht <be…@gmail.com>:


the screen shot that did not get thru::



On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works)

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to
a form element like a text input field?

In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers)
I have found that one can add general form triggers for
"refresh", "onload" and "setup", e.g.
"cur_frm.cscript.refresh = function()". However I need an
"onchange" trigger for a specific text input field, as described
here: http://www.w3schools.com/jsref/event_onchange.asp



I tried the following:

cur_frm.cscript.amount_allocated_on_permit.onchange = function() {

cur_frm.set_value("total_amount_lawfully_used",
999);

refresh_field("total_amount_lawfully_used");

}

but nothing happens, the onchange isn't added to the "amount_allocated_on_permit"
text field.



I need this, because I want to recompute parts of the form when the user
changes some elements. I am trying to avoid adding a "recompute"
button, because that spoils the user's interactive experience. Therefore I need
a trigger that is called when the user made some changes in the form input.



Thank you,


Reply via mail:

For onchange trigger you should write the function with a little chnage:

cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




Note:



If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.



    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6591d0c2-f9c6-44af-b640-dbcc7bf777fd%40googlegroups.com.

For more options, visit https://groups.google.com/groups/opt_out.



--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3




--

Best Regards.

Maxwell Morais
Python Developer powered by Webnotes framework <3



Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CABK1YkNhFHC4GL4B8t8ddL65crwcnUm5dB%2BAWXJ%3DtMsmpf9%3D8Q%40mail.gmail.com.

    For more options, visit https://groups.google.com/groups/opt_out.


On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/4a85afaf-f726-4a11-85eb-bce55f15f550%40googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




Note:

 

If you are posting an issue,

  1. We should be able to replicate it at our end. So please give us as much information as you can. Please see it from the point of view of the person receiving the communication.
  2. Paste your code at http://pastebin.com or http://gist.github.com and send only the URL via email
  3. For sending images, use http://imgur.com or other similar services. Do not send images as attachments. Links are good. Same goes for any file you are going to send.

     

    End of Note



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un...@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/9f1f2d86-e1ea-43f6-b53d-01719e64947c%40googlegroups.com.

    For more options, visit https://groups.google.com/groups/opt_out.
Dear Experts,

Am trying to achieve a similar result and had a look at this article.

Basically for my scenario, I have a custom field called "discount_amount" in the Sales Invoice Item document. I would like to achieve the following:
- When the field "rate" or "price_list_rate" is changed I want to calculate price_list_rate - rate and put the result in the discount_amount field

I made the following custom script in the Sales Invoice Item DocType just to test if changes in rate would call the function:
cur_frm.cscript.custom_rate = function(doc) {
    result_value = doc.price_list_rate - doc.rate;
    cur_frm.set_value("discount_amount", result_value);
}

Unfortunately nothing seemed to work. I tried a msgprint as well and it did not call the necessary. Would anyone be able to shed some light on this?

Thank you very very much.


Javier


On Wednesday, February 19, 2014 11:50:39 PM UTC+8, Robert Becht wrote:
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.



  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/0af461a3-00fe-42be-a853-d1f05a93fdd5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Try this one:

cur_frm.cscript.custom_rate = function(doc, cdt, cdn) {
    var d = locals[cdt][cdn];
    result_value = d.price_list_rate - d.rate;
    frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
}

On Sep 24, 2014, at 8:24 AM, Javier Wong <bo...@gmail.com> wrote:

Dear Experts,

Am trying to achieve a similar result and had a look at this article.

Basically for my scenario, I have a custom field called "discount_amount" in the Sales Invoice Item document. I would like to achieve the following:
- When the field "rate" or "price_list_rate" is changed I want to calculate price_list_rate - rate and put the result in the discount_amount field

I made the following custom script in the Sales Invoice Item DocType just to test if changes in rate would call the function:
cur_frm.cscript.custom_rate = function(doc) {
    result_value = doc.price_list_rate - doc.rate;
    cur_frm.set_value("discount_amount", result_value);
}

Unfortunately nothing seemed to work. I tried a msgprint as well and it did not call the necessary. Would anyone be able to shed some light on this?

Thank you very very much.


Javier


On Wednesday, February 19, 2014 11:50:39 PM UTC+8, Robert Becht wrote:
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/0af461a3-00fe-42be-a853-d1f05a93fdd5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/696484F1-6BC1-40D9-9469-668DD73C8209%40gmail.com.

    For more options, visit https://groups.google.com/d/optout.
Are you setting the trigger on the right field?

is it "discount_rate" or "custom_rate" ?



@rushabh_mehta

On 24-Sep-2014, at 8:24 am, Javier Wong <bo...@gmail.com> wrote:

Dear Experts,

Am trying to achieve a similar result and had a look at this article.

Basically for my scenario, I have a custom field called "discount_amount" in the Sales Invoice Item document. I would like to achieve the following:
- When the field "rate" or "price_list_rate" is changed I want to calculate price_list_rate - rate and put the result in the discount_amount field

I made the following custom script in the Sales Invoice Item DocType just to test if changes in rate would call the function:
cur_frm.cscript.custom_rate = function(doc) {
    result_value = doc.price_list_rate - doc.rate;
    cur_frm.set_value("discount_amount", result_value);
}

Unfortunately nothing seemed to work. I tried a msgprint as well and it did not call the necessary. Would anyone be able to shed some light on this?

Thank you very very much.


Javier


On Wednesday, February 19, 2014 11:50:39 PM UTC+8, Robert Becht wrote:
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/0af461a3-00fe-42be-a853-d1f05a93fdd5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/251D35C4-A558-4610-9C47-888824350774%40gmail.com.

    For more options, visit https://groups.google.com/d/optout.
Dear Nabin / Rushabh,

My mistake earlier, the trigger was mean to be for the "rate" field, so whenever a change is detected on the "rate" field it will calculate the value to be set on the custom "discount_amount" field. 

I tried to put the following custom script in the Sales Invoice Item Doc but it didn't work. It is still not triggering when the Sales Invoice Item rate field value is changed.

cur_frm.cscript.rate = function(doc, cdt, cdn) {
    var d = locals[cdt][cdn];
    result_value = d.price_list_rate - d.rate;
    frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
}

In fact I tried an msgprint within the function as well and it doesn't trigger so I suspect that it is not even hitting this function.

Any ideas? Thanks again.


Javier


On Wednesday, September 24, 2014 1:07:43 PM UTC+8, rushabh wrote:
Are you setting the trigger on the right field?

is it "discount_rate" or "custom_rate" ?



@rushabh_mehta

On 24-Sep-2014, at 8:24 am, Javier Wong <bo...@gmail.com> wrote:

Dear Experts,

Am trying to achieve a similar result and had a look at this article.

Basically for my scenario, I have a custom field called "discount_amount" in the Sales Invoice Item document. I would like to achieve the following:
- When the field "rate" or "price_list_rate" is changed I want to calculate price_list_rate - rate and put the result in the discount_amount field

I made the following custom script in the Sales Invoice Item DocType just to test if changes in rate would call the function:
cur_frm.cscript.custom_rate = function(doc) {
    result_value = doc.price_list_rate - doc.rate;
    cur_frm.set_value("discount_amount", result_value);
}

Unfortunately nothing seemed to work. I tried a msgprint as well and it did not call the necessary. Would anyone be able to shed some light on this?

Thank you very very much.


Javier


On Wednesday, February 19, 2014 11:50:39 PM UTC+8, Robert Becht wrote:
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/0af461a3-00fe-42be-a853-d1f05a93fdd5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/4d051527-a81d-4c9f-bb78-ecef9731e5b3%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.

Put the custom script for Sales Invoice doctype, not for Sales Invoice Item.

On 24 Sep 2014 11:53, "Javier Wong" <bo...@gmail.com> wrote:
Dear Nabin / Rushabh,

My mistake earlier, the trigger was mean to be for the "rate" field, so whenever a change is detected on the "rate" field it will calculate the value to be set on the custom "discount_amount" field.

I tried to put the following custom script in the Sales Invoice Item Doc but it didn't work. It is still not triggering when the Sales Invoice Item rate field value is changed.

cur_frm.cscript.rate = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
result_value = d.price_list_rate - d.rate;
frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
}

In fact I tried an msgprint within the function as well and it doesn't trigger so I suspect that it is not even hitting this function.

Any ideas? Thanks again.


Javier


On Wednesday, September 24, 2014 1:07:43 PM UTC+8, rushabh wrote:
Are you setting the trigger on the right field?

is it "discount_rate" or "custom_rate" ?



@rushabh_mehta

On 24-Sep-2014, at 8:24 am, Javier Wong <bo...@gmail.com> wrote:

Dear Experts,

Am trying to achieve a similar result and had a look at this article.

Basically for my scenario, I have a custom field called "discount_amount" in the Sales Invoice Item document. I would like to achieve the following:
- When the field "rate" or "price_list_rate" is changed I want to calculate price_list_rate - rate and put the result in the discount_amount field

I made the following custom script in the Sales Invoice Item DocType just to test if changes in rate would call the function:
cur_frm.cscript.custom_rate = function(doc) {
result_value = doc.price_list_rate - doc.rate;
cur_frm.set_value("discount_amount", result_value);
}

Unfortunately nothing seemed to work. I tried a msgprint as well and it did not call the necessary. Would anyone be able to shed some light on this?

Thank you very very much.


Javier


On Wednesday, February 19, 2014 11:50:39 PM UTC+8, Robert Becht wrote:
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works)

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh", "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
cur_frm.set_value("total_amount_lawfully_used", 999);
refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/0af461a3-00fe-42be-a853-d1f05a93fdd5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/4d051527-a81d-4c9f-bb78-ecef9731e5b3%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/CA%2BCj7tg7ZSLUKEMpKppSSu5_G-crsyNQi5ncHKwuWjB346pMjw%40mail.gmail.com.

    For more options, visit https://groups.google.com/d/optout.
Dear Nabin,

That worked wonders and the function triggers now. Just for sharing, I decided to put the trigger on the Pricing Rule field at the end of the day as I noticed very odd behaviour when attaching the trigger to fields like qty, price_list_rate and rate --> when using pricing rule it seems to override some default functionality which seem to block the system from writing into the rate field when a pricing rule triggers.

I do have one question though. Similar to the "price_list_rate" field, I would like to disable my custom field from being editable by a user. Can I do that programmatically or from the Customize form?

Thanks so much guys. You are superb.


Javier


On Wednesday, September 24, 2014 2:28:19 PM UTC+8, Nabin Hait wrote:

Put the custom script for Sales Invoice doctype, not for Sales Invoice Item.

On 24 Sep 2014 11:53, "Javier Wong" <bo...@gmail.com> wrote:
Dear Nabin / Rushabh,

My mistake earlier, the trigger was mean to be for the "rate" field, so whenever a change is detected on the "rate" field it will calculate the value to be set on the custom "discount_amount" field. 

I tried to put the following custom script in the Sales Invoice Item Doc but it didn't work. It is still not triggering when the Sales Invoice Item rate field value is changed.

cur_frm.cscript.rate = function(doc, cdt, cdn) {
    var d = locals[cdt][cdn];
    result_value = d.price_list_rate - d.rate;
    frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
}

In fact I tried an msgprint within the function as well and it doesn't trigger so I suspect that it is not even hitting this function.

Any ideas? Thanks again.


Javier


On Wednesday, September 24, 2014 1:07:43 PM UTC+8, rushabh wrote:
Are you setting the trigger on the right field?

is it "discount_rate" or "custom_rate" ?



@rushabh_mehta

On 24-Sep-2014, at 8:24 am, Javier Wong <bo...@gmail.com> wrote:

Dear Experts,

Am trying to achieve a similar result and had a look at this article.

Basically for my scenario, I have a custom field called "discount_amount" in the Sales Invoice Item document. I would like to achieve the following:
- When the field "rate" or "price_list_rate" is changed I want to calculate price_list_rate - rate and put the result in the discount_amount field

I made the following custom script in the Sales Invoice Item DocType just to test if changes in rate would call the function:
cur_frm.cscript.custom_rate = function(doc) {
    result_value = doc.price_list_rate - doc.rate;
    cur_frm.set_value("discount_amount", result_value);
}

Unfortunately nothing seemed to work. I tried a msgprint as well and it did not call the necessary. Would anyone be able to shed some light on this?

Thank you very very much.


Javier


On Wednesday, February 19, 2014 11:50:39 PM UTC+8, Robert Becht wrote:
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubscr…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/0af461a3-00fe-42be-a853-d1f05a93fdd5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/4d051527-a81d-4c9f-bb78-ecef9731e5b3%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6f34b9cd-2244-4fc5-a57e-c3a0ca066b47%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.
Well. If you always want a field to be non editable, you can mark it as read only from the custom field form.  

Sent from my phone

On 25-Sep-2014, at 7:59, Javier Wong <bo...@gmail.com> wrote:

Dear Nabin,

That worked wonders and the function triggers now. Just for sharing, I decided to put the trigger on the Pricing Rule field at the end of the day as I noticed very odd behaviour when attaching the trigger to fields like qty, price_list_rate and rate --> when using pricing rule it seems to override some default functionality which seem to block the system from writing into the rate field when a pricing rule triggers.

I do have one question though. Similar to the "price_list_rate" field, I would like to disable my custom field from being editable by a user. Can I do that programmatically or from the Customize form?

Thanks so much guys. You are superb.


Javier


On Wednesday, September 24, 2014 2:28:19 PM UTC+8, Nabin Hait wrote:

Put the custom script for Sales Invoice doctype, not for Sales Invoice Item.

On 24 Sep 2014 11:53, "Javier Wong" <bo...@gmail.com> wrote:
Dear Nabin / Rushabh,

My mistake earlier, the trigger was mean to be for the "rate" field, so whenever a change is detected on the "rate" field it will calculate the value to be set on the custom "discount_amount" field. 

I tried to put the following custom script in the Sales Invoice Item Doc but it didn't work. It is still not triggering when the Sales Invoice Item rate field value is changed.

cur_frm.cscript.rate = function(doc, cdt, cdn) {
    var d = locals[cdt][cdn];
    result_value = d.price_list_rate - d.rate;
    frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
}

In fact I tried an msgprint within the function as well and it doesn't trigger so I suspect that it is not even hitting this function.

Any ideas? Thanks again.


Javier


On Wednesday, September 24, 2014 1:07:43 PM UTC+8, rushabh wrote:
Are you setting the trigger on the right field?

is it "discount_rate" or "custom_rate" ?



@rushabh_mehta

On 24-Sep-2014, at 8:24 am, Javier Wong <bo...@gmail.com> wrote:

Dear Experts,

Am trying to achieve a similar result and had a look at this article.

Basically for my scenario, I have a custom field called "discount_amount" in the Sales Invoice Item document. I would like to achieve the following:
- When the field "rate" or "price_list_rate" is changed I want to calculate price_list_rate - rate and put the result in the discount_amount field

I made the following custom script in the Sales Invoice Item DocType just to test if changes in rate would call the function:
cur_frm.cscript.custom_rate = function(doc) {
    result_value = doc.price_list_rate - doc.rate;
    cur_frm.set_value("discount_amount", result_value);
}

Unfortunately nothing seemed to work. I tried a msgprint as well and it did not call the necessary. Would anyone be able to shed some light on this?

Thank you very very much.


Javier


On Wednesday, February 19, 2014 11:50:39 PM UTC+8, Robert Becht wrote:
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubscr…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/0af461a3-00fe-42be-a853-d1f05a93fdd5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/4d051527-a81d-4c9f-bb78-ecef9731e5b3%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6f34b9cd-2244-4fc5-a57e-c3a0ca066b47%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/A7D7E593-1D64-43BB-BEA0-62EB2A4EC1CC%40iwebnotes.com.

    For more options, visit https://groups.google.com/d/optout.
Dear Anand,

Is it possible to set the field to read only programmatically? I have a custom field that is of Currency type called "discount_amount" and I want to make it read only after say the pricing rule is triggered. Can I run something like "frappe.model.set_df_property(cdt, cdn, "discount_amount", "read_only", 0);"? It currently doesn't work - perhaps my syntax is wrong....

Appreciate any help. Thank you very much....

The current customer script that I am using "all works except setting the field to read only"

cur_frm.cscript.pricing_rule = function(doc, cdt, cdn) {
    var d = locals[cdt][cdn];
    result_value = d.price_list_rate - d.rate;
    frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
    frappe.model.set_df_property(cdt, cdn, "discount_amount", "read_only", 0);
}


Javier

On Thursday, September 25, 2014 11:32:08 PM UTC+8, Anand Doshi wrote:
Well. If you always want a field to be non editable, you can mark it as read only from the custom field form.  

Sent from my phone

On 25-Sep-2014, at 7:59, Javier Wong <bo...@gmail.com> wrote:

Dear Nabin,

That worked wonders and the function triggers now. Just for sharing, I decided to put the trigger on the Pricing Rule field at the end of the day as I noticed very odd behaviour when attaching the trigger to fields like qty, price_list_rate and rate --> when using pricing rule it seems to override some default functionality which seem to block the system from writing into the rate field when a pricing rule triggers.

I do have one question though. Similar to the "price_list_rate" field, I would like to disable my custom field from being editable by a user. Can I do that programmatically or from the Customize form?

Thanks so much guys. You are superb.


Javier


On Wednesday, September 24, 2014 2:28:19 PM UTC+8, Nabin Hait wrote:

Put the custom script for Sales Invoice doctype, not for Sales Invoice Item.

On 24 Sep 2014 11:53, "Javier Wong" <bo...@gmail.com> wrote:
Dear Nabin / Rushabh,

My mistake earlier, the trigger was mean to be for the "rate" field, so whenever a change is detected on the "rate" field it will calculate the value to be set on the custom "discount_amount" field. 

I tried to put the following custom script in the Sales Invoice Item Doc but it didn't work. It is still not triggering when the Sales Invoice Item rate field value is changed.

cur_frm.cscript.rate = function(doc, cdt, cdn) {
    var d = locals[cdt][cdn];
    result_value = d.price_list_rate - d.rate;
    frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
}

In fact I tried an msgprint within the function as well and it doesn't trigger so I suspect that it is not even hitting this function.

Any ideas? Thanks again.


Javier


On Wednesday, September 24, 2014 1:07:43 PM UTC+8, rushabh wrote:
Are you setting the trigger on the right field?

is it "discount_rate" or "custom_rate" ?



@rushabh_mehta

On 24-Sep-2014, at 8:24 am, Javier Wong <bo...@gmail.com> wrote:

Dear Experts,

Am trying to achieve a similar result and had a look at this article.

Basically for my scenario, I have a custom field called "discount_amount" in the Sales Invoice Item document. I would like to achieve the following:
- When the field "rate" or "price_list_rate" is changed I want to calculate price_list_rate - rate and put the result in the discount_amount field

I made the following custom script in the Sales Invoice Item DocType just to test if changes in rate would call the function:
cur_frm.cscript.custom_rate = function(doc) {
    result_value = doc.price_list_rate - doc.rate;
    cur_frm.set_value("discount_amount", result_value);
}

Unfortunately nothing seemed to work. I tried a msgprint as well and it did not call the necessary. Would anyone be able to shed some light on this?

Thank you very very much.


Javier


On Wednesday, February 19, 2014 11:50:39 PM UTC+8, Robert Becht wrote:
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubscr…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/0af461a3-00fe-42be-a853-d1f05a93fdd5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/4d051527-a81d-4c9f-bb78-ecef9731e5b3%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6f34b9cd-2244-4fc5-a57e-c3a0ca066b47%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/e4ac88b1-784a-4483-8899-5324dbaf98e9%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.

On 26-Sep-2014, at 7:50 am, Javier Wong <bo...@gmail.com> wrote:

Dear Anand,

Is it possible to set the field to read only programmatically? I have a custom field that is of Currency type called "discount_amount" and I want to make it read only after say the pricing rule is triggered. Can I run something like "frappe.model.set_df_property(cdt, cdn, "discount_amount", "read_only", 0);"? It currently doesn't work - perhaps my syntax is wrong....

Appreciate any help. Thank you very much....

The current customer script that I am using "all works except setting the field to read only"

cur_frm.cscript.pricing_rule = function(doc, cdt, cdn) {
    var d = locals[cdt][cdn];
    result_value = d.price_list_rate - d.rate;
    frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
    frappe.model.set_df_property(cdt, cdn, "discount_amount", "read_only", 0);

Should be cur_frm.set_df_property ...

}


Javier

On Thursday, September 25, 2014 11:32:08 PM UTC+8, Anand Doshi wrote:
Well. If you always want a field to be non editable, you can mark it as read only from the custom field form.  

Sent from my phone

On 25-Sep-2014, at 7:59, Javier Wong <bo...@gmail.com> wrote:

Dear Nabin,

That worked wonders and the function triggers now. Just for sharing, I decided to put the trigger on the Pricing Rule field at the end of the day as I noticed very odd behaviour when attaching the trigger to fields like qty, price_list_rate and rate --> when using pricing rule it seems to override some default functionality which seem to block the system from writing into the rate field when a pricing rule triggers.

I do have one question though. Similar to the "price_list_rate" field, I would like to disable my custom field from being editable by a user. Can I do that programmatically or from the Customize form?

Thanks so much guys. You are superb.


Javier


On Wednesday, September 24, 2014 2:28:19 PM UTC+8, Nabin Hait wrote:

Put the custom script for Sales Invoice doctype, not for Sales Invoice Item.

On 24 Sep 2014 11:53, "Javier Wong" <bo...@gmail.com> wrote:
Dear Nabin / Rushabh,

My mistake earlier, the trigger was mean to be for the "rate" field, so whenever a change is detected on the "rate" field it will calculate the value to be set on the custom "discount_amount" field. 

I tried to put the following custom script in the Sales Invoice Item Doc but it didn't work. It is still not triggering when the Sales Invoice Item rate field value is changed.

cur_frm.cscript.rate = function(doc, cdt, cdn) {
    var d = locals[cdt][cdn];
    result_value = d.price_list_rate - d.rate;
    frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
}

In fact I tried an msgprint within the function as well and it doesn't trigger so I suspect that it is not even hitting this function.

Any ideas? Thanks again.


Javier


On Wednesday, September 24, 2014 1:07:43 PM UTC+8, rushabh wrote:
Are you setting the trigger on the right field?

is it "discount_rate" or "custom_rate" ?



@rushabh_mehta

On 24-Sep-2014, at 8:24 am, Javier Wong <bo...@gmail.com> wrote:

Dear Experts,

Am trying to achieve a similar result and had a look at this article.

Basically for my scenario, I have a custom field called "discount_amount" in the Sales Invoice Item document. I would like to achieve the following:
- When the field "rate" or "price_list_rate" is changed I want to calculate price_list_rate - rate and put the result in the discount_amount field

I made the following custom script in the Sales Invoice Item DocType just to test if changes in rate would call the function:
cur_frm.cscript.custom_rate = function(doc) {
    result_value = doc.price_list_rate - doc.rate;
    cur_frm.set_value("discount_amount", result_value);
}

Unfortunately nothing seemed to work. I tried a msgprint as well and it did not call the necessary. Would anyone be able to shed some light on this?

Thank you very very much.


Javier


On Wednesday, February 19, 2014 11:50:39 PM UTC+8, Robert Becht wrote:
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubscr…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/0af461a3-00fe-42be-a853-d1f05a93fdd5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.



  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/4d051527-a81d-4c9f-bb78-ecef9731e5b3%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6f34b9cd-2244-4fc5-a57e-c3a0ca066b47%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/e4ac88b1-784a-4483-8899-5324dbaf98e9%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/177EE034-C648-4AE0-9EF0-A0D3DFDACF33%40gmail.com.

    For more options, visit https://groups.google.com/d/optout.
Dear Rushabh,

Thanks for the recommendation. This would only work if the field is in the main form.

In my scenario I am running the script on the Sales Order DocType but the field I want to make read_only is within the Sales Order Item form.

Just as an example, once there is a change in the qty within the Sales Order Item form I want to disable the qty field.

The following script was created in the Sales Order form.

cur_frm.cscript.qty = function(doc, cdt, cdn) {
    cur_frm.set_df_property("qty", "read_only", true);
}

Appreciate any help. Thank you very much.


Javier


On Friday, September 26, 2014 1:55:37 PM UTC+8, rushabh wrote:

On 26-Sep-2014, at 7:50 am, Javier Wong <bo...@gmail.com> wrote:

Dear Anand,

Is it possible to set the field to read only programmatically? I have a custom field that is of Currency type called "discount_amount" and I want to make it read only after say the pricing rule is triggered. Can I run something like "frappe.model.set_df_property(cdt, cdn, "discount_amount", "read_only", 0);"? It currently doesn't work - perhaps my syntax is wrong....

Appreciate any help. Thank you very much....

The current customer script that I am using "all works except setting the field to read only"

cur_frm.cscript.pricing_rule = function(doc, cdt, cdn) {
    var d = locals[cdt][cdn];
    result_value = d.price_list_rate - d.rate;
    frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
    frappe.model.set_df_property(cdt, cdn, "discount_amount", "read_only", 0);

Should be cur_frm.set_df_property ...

}


Javier

On Thursday, September 25, 2014 11:32:08 PM UTC+8, Anand Doshi wrote:
Well. If you always want a field to be non editable, you can mark it as read only from the custom field form.  

Sent from my phone

On 25-Sep-2014, at 7:59, Javier Wong <bo...@gmail.com> wrote:

Dear Nabin,

That worked wonders and the function triggers now. Just for sharing, I decided to put the trigger on the Pricing Rule field at the end of the day as I noticed very odd behaviour when attaching the trigger to fields like qty, price_list_rate and rate --> when using pricing rule it seems to override some default functionality which seem to block the system from writing into the rate field when a pricing rule triggers.

I do have one question though. Similar to the "price_list_rate" field, I would like to disable my custom field from being editable by a user. Can I do that programmatically or from the Customize form?

Thanks so much guys. You are superb.


Javier


On Wednesday, September 24, 2014 2:28:19 PM UTC+8, Nabin Hait wrote:

Put the custom script for Sales Invoice doctype, not for Sales Invoice Item.

On 24 Sep 2014 11:53, "Javier Wong" <bo...@gmail.com> wrote:
Dear Nabin / Rushabh,

My mistake earlier, the trigger was mean to be for the "rate" field, so whenever a change is detected on the "rate" field it will calculate the value to be set on the custom "discount_amount" field. 

I tried to put the following custom script in the Sales Invoice Item Doc but it didn't work. It is still not triggering when the Sales Invoice Item rate field value is changed.

cur_frm.cscript.rate = function(doc, cdt, cdn) {
    var d = locals[cdt][cdn];
    result_value = d.price_list_rate - d.rate;
    frappe.model.set_value(cdt, cdn, "discount_amount", result_value);
}

In fact I tried an msgprint within the function as well and it doesn't trigger so I suspect that it is not even hitting this function.

Any ideas? Thanks again.


Javier


On Wednesday, September 24, 2014 1:07:43 PM UTC+8, rushabh wrote:
Are you setting the trigger on the right field?

is it "discount_rate" or "custom_rate" ?



@rushabh_mehta

On 24-Sep-2014, at 8:24 am, Javier Wong <bo...@gmail.com> wrote:

Dear Experts,

Am trying to achieve a similar result and had a look at this article.

Basically for my scenario, I have a custom field called "discount_amount" in the Sales Invoice Item document. I would like to achieve the following:
- When the field "rate" or "price_list_rate" is changed I want to calculate price_list_rate - rate and put the result in the discount_amount field

I made the following custom script in the Sales Invoice Item DocType just to test if changes in rate would call the function:
cur_frm.cscript.custom_rate = function(doc) {
    result_value = doc.price_list_rate - doc.rate;
    cur_frm.set_value("discount_amount", result_value);
}

Unfortunately nothing seemed to work. I tried a msgprint as well and it did not call the necessary. Would anyone be able to shed some light on this?

Thank you very very much.


Javier


On Wednesday, February 19, 2014 11:50:39 PM UTC+8, Robert Becht wrote:
Hi Maxwell, thanks a lot, we have it up and running, rgds robert

On Tuesday, February 18, 2014 8:51:34 AM UTC+1, Robert Becht wrote:


Description of functionality we try to implement.
Copy start en end data custom fields from invoice to Invoice _items (works)
Calc number of days in invoice item (works) 

Fetch a number from a customfield in Item database (works)

Multiply the calculated number of days with the constant from database. (works)

hat does not work??

recalculation if the user changes the inputs. How do we triggger the recalc after input is changed.



How can I add an "onchange" trigger to a form element like a text input field?
In the cookbook (http://wnframework.readthedocs.org/en/latest/client_side_cookbook.html#form-events-triggers) I have found that one can add general form triggers for "refresh",  "onload" and "setup", e.g. "cur_frm.cscript.refresh = function()". However I need an "onchange" trigger for a specific text input field, as described here: http://www.w3schools.com/jsref/event_onchange.asp

I tried the following:
cur_frm.cscript.amount_allocated_on_permit.onchange = function() {
    cur_frm.set_value("total_amount_lawfully_used", 999);
    refresh_field("total_amount_lawfully_used");
}
but nothing happens, the onchange isn't added to the "amount_allocated_on_permit" text field.

I need this, because I want to recompute parts of the form when the user changes some elements. I am trying to avoid adding a "recompute" button, because that spoils the user's interactive experience. Therefore I need a trigger that is called when the user made some changes in the form input.

Thank you,

Reply via mail:

For onchange trigger you should write the function with a little chnage:

 cur_frm.cscript.amount_allocated_on_permit = function() {

cur_frm.set_value("total_amount_lawfully_used", 999);

}

 You do not need to refresh field, as set_value function automatically refresh after setting the value.

Reply back::
Thank you for this suggestion, however this does not trigger when the user has typed new text in the text field called "amount_allocated_on_permit", not even when the user leaves the text field by clicking on another field.
It does trigger once when the form loads, but I can't get it to trigger again.




  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+unsubscr…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/0af461a3-00fe-42be-a853-d1f05a93fdd5%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.



  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/4d051527-a81d-4c9f-bb78-ecef9731e5b3%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/6f34b9cd-2244-4fc5-a57e-c3a0ca066b47%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don’t send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups “ERPNext Developer Forum” group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/e4ac88b1-784a-4483-8899-5324dbaf98e9%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.


  1. Please be kind and don't send large attachments
  2. For issues, features requests use https://github.com/frappe/erpnext/issues



    You received this message because you are subscribed to the Google Groups "ERPNext Developer Forum" group.

    To unsubscribe from this group and stop receiving emails from it, send an email to erpnext-developer-forum+un…@googlegroups.com.

    To view this discussion on the web visit https://groups.google.com/d/msgid/erpnext-developer-forum/b4cee0a5-f357-4bb1-ba8e-0251de7beda7%40googlegroups.com.

    For more options, visit https://groups.google.com/d/optout.