Multiple fields on change triggers one function

Hi,

I have a table of 18 dates (3x6) and a status that is calculated for each set of 3 with the same formula.

Stage1EstimatedDate Stage1PlannedDate Stage1ActualDate Stage1Status
Stage2EstimatedDate Stage2PlannedDate Stage2ActualDate Stage2Status
etc...

To run the status calculation function, I'll need to write an on change for each field.

Is there a way of grouping the fields into 6 groups (with an OR, maybe) so that they only need one on change function to run the status calculation formula? Such that if any field in the group of three is changed, the function is passed the three dates and runs.

Thanks
Nick

Dear @Nick.Jones,
Of course, you can run the same function with multiple events, like this:

fd.spRendered(function() {
    function myFunction() {
        //do something
    }

    // Calling myFunction when Status value changes
    fd.field('Status').$on('change',myFunction);

     // Calling myFunction when Title value changes
    fd.field('Title').$on('change',myFunction);

});
1 Like

Hi @Nikita_Kurguzov ,

I was hoping there would be a shortcut to group fields, maybe something like

(fd.field('Status'), fd.field('Title'), fd.field('AnotherField')).$on('change',myFunction);

Is there anything like this available, or does each field have to have it's own on change line?

Regards
Nick

Dear @Nick.Jones,
If you want to shorten the code, you can place all fields in one array and loop through it:

fd.spRendered(function() {
    function myFunction() {
        //do something
    }

    var fields = ['Title', 'Status', 'AnotherField'];
    for (var x in fields) {
         fd.field(fields[x]).$on('change',myFunction);
    }
});
1 Like

Hi @Nikita_Kurguzov ,

That's just what I was looking for!

Thank you

Regards
Nick