Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
60
How to set igCombo selectedItem to another field
posted

I have an igCombo that on page load, selects an item as the default.  I am trying to set this selected value to another hidden form field called "OrderTypeHidden", that I have created, but do not know how to get the selecteditem.

 

<div id="combo_OrderTypes"></div>

<input type="text" name="OrderTypeHidden" id="OrderTypeHidden">

<script>

$.get("../order/Json_OrderTypes", function (data) {
//Get
$("#combo_OrderTypes").igCombo({
dataSource: data,
selectedItems: [{ index: 5 }, { text: "S" }],
valueKey: "Order_Type",
textKey: "Order_Type",
width: "100px",
dropDownWidth: 500,
itemTemplate: "<div class='comboItemContainer'><div class='colOne'>${Order_Type}</div><div class='colTwo_NoDash'>${Description}</div></div>"

});

$("#combo_OrderTypes").igCombo("setFocus");

}, "json");

</script>

Parents
No Data
Reply
  • 17590
    Suggested Answer
    Offline posted

    Hello James,

    Thank you for posting in our community.

    What I can suggest for getting the selected item is using selectedIndex method of the igCombo API. With this method the index of currently selected item could be retrieved. Afterwards, the item itself could be accessed using itemByIndex method. This could be achieve as following:

    [code]

      <script>
             $(function () {

                 var data = [
                           { "ID": 1, "Name": "John Smith", "Age": 45 },
                           { "ID": 2, "Name": "Mary Johnson", "Age": 32 },
                           { "ID": 3, "Name": "Bob Ferguson", "Age": 27 }
                 ];

                 $("#combo").igCombo({
                     dataSource: data, //JSON Array defined above   
                     selectedItems: [{ index: 1 }],
                     valueKey: "ID",
                     textKey: "Name"
                 });
                
                //get selected item index
                 var index = $("#combo").igCombo("selectedIndex");
                 //get the item with the corresponding index
                 var item = $("#combo").igCombo("itemByIndex", index);
                 //get item`s text
                 var text = item.text;
                 //set hidden input value
                 $("#Hidden1").val(text);
                 alert($("#Hidden1").val());
                 //debugger;
              
             });
        </script>

    [/code]

    I made a msall project and I am attaching it for your reference.

    In my sample initially, there is a selected item from the combo. Afterwards I am getting item`s index and the item itself. Hidden`s field value is set and afterwards an alert with the values appears.

    I believe you might consider the following link to the igCombo`s API useful:

    help.infragistics.com/.../ui.igcombo

    I hope you find this information helpful.

    Please let me know if you need any further assistance with this matter.

    igComboSetHiddenFieldValue.zip
Children