Javascript event handlers question

Javascript event handlers question

divad.thgirbladivad.thgirbla Posts: 36Questions: 14Answers: 1

I'm trying to use a javascript onchange() event handler on my Editor fields. Specifically, numeric fields so that I can check that the values meet certain criteria. The field definition looks like this:

{label: 'W2', name: 'W2_Amount', id: 'W2_Amount', type: 'text', attr:{onchange:'myChange(this)',classname:'numericField2',type:'number',maxlength:13, min:'0', max:'99999999', step:'0.01'} }

The onchange() event handler executes when the field value changes, which is what I want, but it also executes when the Editor page first displays for every field that has an onchange() event handler, which is what I don't want. My guess is that the initial page load's values go from uninitialized to a value, triggering the event handler for each field, when the page loads. Is there a way to bypass the initial triggering on a page load? Or should I be handling event handlers a different way?

This question has an accepted answers - jump to answer

Answers

  • colincolin Posts: 15,142Questions: 1Answers: 2,586
    Answer ✓

    I'd be tempted to use dependent() instead of onchange() - it will get triggered only on a change, and will be within Editor.

    If you use onchange(), I'd imagine you would need to remove the exiting triggers in preClose, and re-add again once the form is fully opened and the data present in the opened,

    Colin

  • divad.thgirbladivad.thgirbla Posts: 36Questions: 14Answers: 1

    Using the dependent() function helped solve this issue.

    Thanks

This discussion has been closed.