Note that according to the documentation at Customization to reset a value, we need to invoke frappe.web_form.set_value(). However, if this is done within the event handler, as is indicated in the documentation, then this leads to an infinite loop, for specific values such as null, undefined, “”, NaN, etc. This freezes the browser
What we really need is the ability to not trigger the event handler as is the case with frm.set_value() for DocType Form Views. This function has an argument skip_dirty_trigger=true which the web_form.set_value() does not have.
This is an event handler associated with the Web Form field “subject”. My dilemma is that it triggers when I update the very same field (aka “subject”) with field.set_value(). I don’t want the event handler to trigger on all occasions, especially when set_value() is called from within the event handler, as below.
What I mean with field.set_value(undefined) is to reset it’s value to nothing, which is very much fieldtype dependent.
If it’s a Data, Small Text, Phone, etc then you can reset it’s value to any one of “”, null, undefined, etc
If it’s Int, Currency, etc then you can reset to 0, null, undefined, etc
In essence how do you remove any value currently in the field, ie clear it.
This is based directly on the example from the documentation at Customization wich I copy here for convenience.
frappe.web_form.on('amount', (field, value) => {
if (value < 1000) {
frappe.msgprint('Value must be more than 1000');
field.set_value(0);
}
});
Note that in this case field.set_value(0) will still trigger the frappe.web_form.on() event handler but only once, as the second call to field.set_value(0) will deem the field not to be dirty. BUT, this is not always the case and in the event of field.set_value(undefined) or field.set_value(“”) it keeps triggering the event handler. It creates an infinite loop.
Copy and paste my 5 lines of JS into the .js file of a Web Form and execute it. Your browser freezes up!!!