You can use JQuery for changing the data set of another text input (auto-complete) on selecting an option of first text input with (auto-complete).
In this example, on selection of the option in input1, we are calling an CAPI, passing the selected value as input parameter of the CAPI, based on he input parameter, 2nd text input data set is retrieved, once result is loaded in browser, we are setting the data set of the second input.
you can customize the below code removing the call to the CAPI and setting the dataset of the 2nd text input directly inside the "onSelectInput1" method.
availableTags = [];
var dataSecondInput = [];
jQuery("#id_input1").autocomplete({
/* Array that contains entries */
source : availableTags,
/* Focus 1st entry on default */
autoFocus : true,
select : onSelectInput1,
/* Number of characters from which it launch the search in collection */
minLength : 1
});
jQuery("#id_input2").autocomplete({
/* Array that contains entries */
source : dataSecondInput,
select : onSelectInput2,
/* Number of characters from which it launch the search in collection */
minLength : 1
});
function onSelectInput1(event, ui){
dataSecondInput = [];
$("#id_input2").val("");
var input = {"data_type":jQuery("#id_input1").val()};
var options = {};
id_capi_get_second_dataSet.trigger(input,options,list_ok_second,list_ko_second);
}
function list_ko_second(result) {
alert("Error in the id_capi_get_second_dataSet: " + JSON.stringify(result));
}
/* Function if List on collection is completed */
function list_ok_second(result) {
dataSecondInput = [];
//alert(JSON.stringify(result))
for (i = 0; i < result.length; i++) {
dataSecondInput.push({
}
// Reset Autocomplete widget for next use
jQuery("#id_input2").autocomplete({
source : dataSecondInput
});
}
function onSelectInput2(event, ui){
var arr = ui.item.value.split("-");
//todo as the business logic
}
// end of js code.