Is it possible to make dependent fields only trigger on user actions, and not on dialog toggle?

Is it possible to make dependent fields only trigger on user actions, and not on dialog toggle?

amemonamemon Posts: 3Questions: 2Answers: 0
edited October 2019 in Free community support

I'm using dependent to bind a couple of fields. dependent fields seem to be implicitly triggered when the new/edit dialog is shown, but I want the values to be overridden only if the user actually changes the field.

            // Only trigger when the user makes a new selection
            editor.dependent('selectbox', (val, data, callback) => {
                const selection = dict[val];

                return {
                    values: {
                        'inputfield': selection
                    },
                };
            }, { event: 'change' });

Thank you

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 61,439Questions: 1Answers: 10,053 Site admin
    Answer ✓

    Hi,

    It has to be triggered when create and edit are started since they can set values (default or existing value) and the rest of the form should reflect those values.

    but I want the values to be overridden only if the user actually changes the field.

    Which field - the selectbox or inputfield?

    You can listen for the change event from the input field and if there is a second parameter then Editor set the value - e.g.:

    editor.field('myField').input().on('change', function (e, d) {
      if ( !d || !d.editor ) {
        // The change was triggered by the end user rather than an auto set
      }
    });
    

    Allan

  • amemonamemon Posts: 3Questions: 2Answers: 0

    Perfect. Thanks!

This discussion has been closed.