Autofill selectize.js

Autofill selectize.js

antoniocibantoniocib Posts: 277Questions: 62Answers: 1

Hello, I have a somewhat difficult question, at least for me, in inserting a row in the DataTable I implemented Selectize.js, I wanted that when I validate the field of the type, example:

City = New York

automatically the second field is filled in this way:

Country = USA

I hope I was clear, thank you in advance!

Answers

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

    just use "dependent" with a simple look up table: Whenever the selected value changes you fill the second field with the respective look up table value.

    I assume your Editor fields are called "city" and "country".

    editor
        .dependent('city', function (val, data, callback) {
            var arr =
            [
                { city: "New York", country: "USA" },
                { city: "Münster", country: "Deutschland" },
                { city: "Roma", country: "Italia" },
                { city: "Milano", country: "Italia" },
                { city: "Napoli", country: "Italia" },
                { city: "Madrid", country: "España" }
            ];
            var country = $.grep(arr, function(obj){return obj.city == val;})[0].country;
            this.field('country').set(country);
            callback({});
        })
    

    I didn't test this! I hope I got the "$.grep" right.

Sign In or Register to comment.