Use of editor.dependent afer editor.clear and editor.add

Use of editor.dependent afer editor.clear and editor.add

GargiucnGargiucn Posts: 109Questions: 30Answers: 0

I define in editor a hidden "response" field which in editor.open I delete and regenerate with the same name but different type (text, radio, etc...) using editor.clear and editor.add.
But now I would like to parse the contents of the "response" field before filling in the subsequent fields but editor.dependent does not work.
How can I do this?

Thank you,
Giuseppe

This question has an accepted answers - jump to answer

Answers

  • rf1234rf1234 Posts: 3,006Questions: 87Answers: 421
    edited February 2023

    I have this field that is deleted and added dynamically:

    }, {
        label: lang === 'de' ? 'Abteilungsauswahl:' : 'Department Selection:',
        name:  "ctr_govdept[].id", //removed and added dynamically
        type: "selectize" //must be a selectize field ALWAYS!!
    }, {
    

    On "open" of Editor I do this (also replacing "dependent" with jQuery):

    this.clear( "ctr_govdept[].id" ); 
    this.add( {
        label: lang === 'de' ? 'Abteilungsauswahl:' : 'Department selection:',
        name: "ctr_govdept[].id", 
        type: "selectize",
        options: ctrGovdeptOptions,
        opts: {
            create: false,
            maxItems: null,
            openOnFocus: true,
            allowEmptyOption: false,
            placeholder: lang === 'de' ? 'Bitte wählen Sie eine oder mehrere Abteilungen' : 'Please select one or more departments',
        }
    }, "sub.sub_partner_id" );
    $( this.field('ctr_govdept[].id').node() ).change( function() {
       ... parse your field or whatever
    });
    //trigger the first change - just like "dependent":
    $( this.field('ctr_govdept[].id').node() ).change();
    

    On "close" of Editor I do this:

    $( this.field('ctr_govdept[].id').node() ).off( 'change' );
    

    You can also shove "dependent" into an event handler like this which could also be an option for you:

    editor
        .on('initCreate', function () {
            this.dependent('fixed.first_payment_date', function (val, data, callback) {
                this.set( 'fixed.following_payment_day', val.substr(0,2) );
                callback({});
            })           
        })
    
  • GargiucnGargiucn Posts: 109Questions: 30Answers: 0

    Thank you for your response.
    In my case I can't use 'initCreate' because all the rows in the table have already been generated, so I work everything in 'Edit'.
    Can I use the same system?

    Giuseppe

  • rf1234rf1234 Posts: 3,006Questions: 87Answers: 421
    Answer ✓

    Sure, why not. Just use an event handler that works for you.

Sign In or Register to comment.