avoid dependency

avoid dependency

karthik.rkarthik.r Posts: 20Questions: 3Answers: 0

Hello allan

I am facing a problem on dependency ..

for example

editor.dependent('date', function(val, data, callback){

editor.field('name').set('10');

)};

for the example shown above...

when i change 'date' field i need to set value 10 to 'name' field..
But if already i have a data in that field.. That should show that value in that field when i open that editor forum.. not dependent value ..
because if we written any caluculation part ..
it will caluculate that value while opening forum so i need to change only value to 'name' field only when 'date' field changed...

so just i showed you an example..
i need to avoid first time dependency while opening editor forum and rest work for all iteration ...

regards
karthik.r
Agiliti

Replies

  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin

    Hi Agiliti,

    The data parameter that is passed in has the original values for the fields and also their current values (e.g. data.row.date for the original value, data.values.date for the current value). What you could do is check to see if those values are different from the val parameter that is passed in and then use a simple if condition to decide if you need to do the update or not.

    Allan

  • karthik.rkarthik.r Posts: 20Questions: 3Answers: 0

    hello allan ,

    it works but when i switched to the same parameter after changed from another parameter to the same what i got value when poped up in a same iteration...

    for example i have value 10-12-2017 in 'date' field.. when i selected to 20-12-2017 and then reverse back to 10-12-2017 it wont works....

    so i am asking thier is any option that i can avoid first dependency when it pop up editore forum

    now actually i am keeping a flag to set that flag after it opens and disables after editor forum closes ...

    is thier any alternative methods for these problem

    regards
    karthik.r

  • allanallan Posts: 63,683Questions: 1Answers: 10,498 Site admin

    Not really. The dependent() callback has to fire when the field is updated with the value to be edited (since it would need to take account of the fact that the value to be edited is unlikely to be the value that was previously edited).

    The only workaround I can think of would be to listen for the change event on the input element directly (i.e. don't use dependent()). When Editor sets the value (i.e. when editing starts) it will send an editor property in the data object for the callback:

    editor.field( 'myField' ).input().on( 'change', function ( e, d ) {
      if ( ! d.editor ) {
        // It was the user that changed the value, do something
        ...
      }
    } );
    

    Allan

This discussion has been closed.