Dependent

Dependent

modyking55modyking55 Posts: 14Questions: 7Answers: 0
  1. I Want To select zone then it load places into zone dependent using show and hide options into the select field but i need to retrieve multi columns like (name , parent)
    then filter with parent ?

Replies

  • allanallan Posts: 61,665Questions: 1Answers: 10,096 Site admin

    Using the dependent() method sounds like the way to go here. You can have it make an Ajax request to get any options from a database (if you need that) and also set other field values.

    Allan

  • rf1234rf1234 Posts: 2,806Questions: 85Answers: 406
    edited January 2018

    As a start you could look at this example as well:
    https://editor.datatables.net/examples/api/dependentFields

    and here is an example from my own coding:

    contractEditor
            //preset Iban with saved iban from table govdept as soon as department
            //is being selected
            .dependent('contract.govdept_id', function (val, data, callback) {
                //if the govdept id is filled and the iban isn't set yet   
    //              if ( val > '0' && contractEditor.val('contract.iban') <= '' ) {
                if (val > '0' && data.values['contract.iban'] <= '') {
                    $.ajax({
                        type: "POST",
                        url: 'actions.php?action=getIban',
                        async: true,
                        data: {govdeptId: val},
                        dataType: "json",
                        success: function (data) {
                            return contractEditor.
                                    set({'contract.iban': data.iban});
                        }
                    });
                }
            })
            .dependent('contract.expired', function (val, data, callback) {
                if (val == '1') {
                    contractEditor
                            .show(['contract.exp_date']);
                    if (contractEditor.val('contract.exp_date') <= '') {
                        contractEditor
                            .field('contract.exp_date').set(yesterday);
                    }
                } else {
                    contractEditor
                            .set({'contract.exp_date': ''})
                            .hide(['contract.exp_date']);
                }
            })
    
This discussion has been closed.