selectize.js remote fills other input selectize.js remote fills other input json json

selectize.js remote fills other input


I managed to get it done thanks to @Comte comment, here is the solution

$('#location').selectize({        valueField: 'formatted_address',        labelField: 'formatted_address',        searchField: 'formatted_address',        maxItems: 1,        delimiter: ';',        create: false,        load: function (query, callback) {            if (!query.length) return callback();            $.ajax({                url: "googleloc",                type: 'GET',                dataType: 'json',                data: {                    search: query,                },                error: function () {                    callback();                },                success: function (res) {                    callback(res.results);                    googresults = res.results;                }            });        },        onChange: function (value) {            if (!value.length) return;            for (var key in googresults) {                if (googresults[key].formatted_address == value) {                    var lat = googresults[key].geometry.location.lat;                    var lng = googresults[key].geometry.location.lng;                }            }            $('#latitude').val(lat);            $('#longitude').val(lng);        }    });