sergiodlopes / jquery-flexdatalist

Flexible input autocomplete/datalist plugin for jQuery
http://projects.sergiodinislopes.pt/flexdatalist/
MIT License
365 stars 84 forks source link

flexdatalist - Change data-url sources based on Field Relative in Chained Relative #213

Open tonemine opened 5 years ago

tonemine commented 5 years ago

Hi, (not sure if this is the correct place/way to report a support issue, apologies if incorrect but hoping for some speedy support from anyone that can solve this please!)

My form has a Field Relative #1 and a Chained Relative #2 using the example provided. I'm looking for the way if a user selects 'Afghanistan' in #1 the data source 'data-url='xxx.json'' in #2 is changed to 'data-url=Afghanistan.json'? This is avoid using a single large dataset.

Appreciate the help, many thanks!

sergiodlopes commented 5 years ago

Hi @tonemine,

Why don't you create the #2 input/field when selecting the relative #1?

$('input.flexdatalist').on('change:flexdatalist', function (event, set) {
    $('input.flexdatalist-country').remove();

    var $newInput = $('<input type="text">').attr({
           'data-url' : set.value + '.json',
           'class' : 'flexdatalist-country'
     }).flexdatalist();

    // Insert $newInput where you need it to be...
});

Hope it helps!

Cheers

tonemine commented 5 years ago

Hi Sergio :) Really appreciate the help, unfortunately I still appear to be messing this up! Probably something simple Im doing wrong or not-understanding, please can you take a look/edit the code below to help me fly right as I really like your autocomplete! Many thanks. sergioauto.txt