I have a different situation when the values โโof the drop-down list are already hardcoded. There are only 12 areas, so the jQuery Autocomplete UI user interface is not populated with code.
The solution is much simpler. Because I had to wade through other messages, where it was assumed that the control was loading dynamically, did not find what I needed, and then finally figured it out.
So, where you have the HTML, as shown below, the installation of the selected index is set like this: pay attention to the input part, which is in addition to the dropdown id:
$('#project-locationSearch-dist-input').val('1'); <label id="lblDistDDL" for="project-locationSearch-input-dist" title="Select a district to populate SPNs and PIDs or enter a known SPN or PID." class="control-label">District</label> <select id="project-locationSearch-dist" data-tabindex="1"> <option id="optDistrictOne" value="01">1</option> <option id="optDistrictTwo" value="02">2</option> <option id="optDistrictThree" value="03">3</option> <option id="optDistrictFour" value="04">4</option> <option id="optDistrictFive" value="05">5</option> <option id="optDistrictSix" value="06">6</option> <option id="optDistrictSeven" value="07">7</option> <option id="optDistrictEight" value="08">8</option> <option id="optDistrictNine" value="09">9</option> <option id="optDistrictTen" value="10">10</option> <option id="optDistrictEleven" value="11">11</option> <option id="optDistrictTwelve" value="12">12</option> </select>
Something else that emerged in the Autocomplete control is how to properly disable / empty it. We have 3 controls that work together, 2 of which are mutually exclusive:
//SPN spnDDL.combobox({ select: function (event, ui) { var spnVal = spnDDL.val(); //fire search event $('#project-locationSearch-pid-input').val(''); $('#project-locationSearch-pid-input').prop('disabled', true); pidDDL.empty(); //empty the pid list } }); //get the labels so we have their tool tips to hand. //this way we don't set id values on each label spnDDL.siblings('label').tooltip(); //PID pidDDL.combobox({ select: function (event, ui) { var pidVal = pidDDL.val(); //fire search event $('
Some of them are beyond the scope of the publication, and I do not know where to express it. Since it is very useful and took some time to figure out, it was split.
Und Also ... to enable such a control, it (disabled, false) and NOT (enabled, true) - it also took a little time to understand. :)
The only thing to note besides publishing is:
Everyone shared because it took too long to learn these things on the fly. Hope this will be helpful.
user1585204 Mar 14 '17 at 11:55 2017-03-14 11:55
source share