How to Disable Editor Dependent on Action Edit

How to Disable Editor Dependent on Action Edit

vincmeistervincmeister Posts: 136Questions: 36Answers: 4

Hello Allan,

How to Disable Editor Dependent on Action Edit.
For example, i have 2 select fields, country and city.
I find this answer from you, but not help me much.

Is there any built in function to disable dependent on edit? Please advise, thank you

Answers

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    No - there isn't a built in method for that I'm afraid. I'm not clear on why you wouldn't want that relationship to apply during edit?

    However, what you could do is:

    $( editor.field('myField').input() ).off( 'change keyup' );
    

    which would disable the dependent() action (since all it really does is use an event listener itself).

    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4
    edited January 2018

    I'm not clear on why you wouldn't want that relationship to apply during edit?

    Because the city's field already selected on create process
    when user edit the record, the select box back to the first option of the list

    Please advise, thank you

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    Did you try the $().off() command I suggested above?

    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4

    Hi Allan,

    I try this

    editor.on('open', function(e, mode, action) {
        $( editor.field('city').input() ).off( 'change keyup' );
    });
    

    but the city's field appear blank when editor open. Is that what you mean? Need more help, thank you

  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    You asked how to remove the dependent action, and the above code should do that. I presume your dependent() action is on the Provinsi field? If so, that is the one you would run the $().off() method on to remove its event listener.

    Allan

  • vincmeistervincmeister Posts: 136Questions: 36Answers: 4
    edited January 2018

    Yes

    editor.dependent( 'province', '../usersc/function/load_cities.php' );
    
    editor.on('open', function(e, mode, action) {
        $( editor.field('province').input() ).off( 'change keyup' );
    });
    

    but when the form opened, the city's field change to 1st option of the list

    1.jpg 31.9K
  • allanallan Posts: 61,451Questions: 1Answers: 10,055 Site admin

    That suggests that the actual value of the city isn't in the select list. Can you give me a link to the page showing the issue so I can check that please?

    Allan

  • rf1234rf1234 Posts: 2,801Questions: 85Answers: 406

    @vincmeister

    replace ".input()" with ".node()". Then it should work if you've got the right field.
    Just tried it myself.

This discussion has been closed.