Dynamic autocomplete query

756 views
Skip to first unread message

andre.fc....@gmail.com

unread,
May 6, 2015, 11:13:35 AM5/6/15
to suppor...@runmyprocess.com
Hi all,

Does anyone knows if it's possible to "inject" dynamic values in autocomplete query?

I have a text input with autocomplete and when I select an option, I want to change the autocomplete dataset of another text input.

Thanks!

Pankaj Kumar

unread,
May 9, 2015, 5:56:45 AM5/9/15
to suppor...@runmyprocess.com, andre.figuei...@ts.fujitsu.com, André Figueiredo
Hi Andre,

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).

Please find the sample code as follows:-

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.

//JS Code:-

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({
            "label" : result.id+"-"+result.name,"value" : result.id+"-"+result.name});
    }
    // 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.


Thanks & Regards,
Pankaj Kumar



--
Fujitsu - RunMyProcess
---
You received this message because you are subscribed to the Google Groups "Fujitsu RunMyProcess Developer Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to supportforum...@runmyprocess.com.
To post to this group, send email to suppor...@runmyprocess.com.
Visit this group at http://groups.google.com/a/runmyprocess.com/group/supportforum/.
To view this discussion on the web visit https://groups.google.com/a/runmyprocess.com/d/msgid/supportforum/3b67ac87-fec2-4392-95c1-495798d4325e%40runmyprocess.com.
For more options, visit https://groups.google.com/a/runmyprocess.com/d/optout.

Reply all
Reply to author
Forward
0 new messages