2

for one of my extensions i need to update a select list by ajax. the whole ajax call is working and i got the new option vars for the select list. I add those options in the ajax's "success" function like so:

jQuery('select#jform_identificator').append(new Option("label", "value"));

this part is ok, if i check the source code the options where set. but it does not update the field rendering unfortunately. So my select list still contains no values.

how can i call the updater / refresh the rendering for a select list in joomla's backend? (we are talking here about a default form field).

Edit: This is the innerHTML of the control container:

<select id="jform_scored_team" name="jform[scored_team]" style="display: none;">
     <option value="1">Team A</option>
     <option value="2">Team B</option>
</select>
<div class="chzn-container chzn-container-single chzn-container-single-nosearch" style="width: 220px;" title="" id="jform_scored_team_chzn">
<a class="chzn-single chzn-default">
 <span>Select an option</span>
 <div>
      <b></b>
 </div>
</a>
<div class="chzn-drop">
  <div class="chzn-search">
     <input type="text" autocomplete="off" readonly=""></div>
     <ul class="chzn-results"></ul>
  </div>
</div>

To be honest - the field was created by Joomla Component Builder i disabled all "fancy" options so no search is active for this list.

  • Are you getting any errors in the browser console? Are you sure jform_identificator is the correct ID of the element? – Lodder May 26 at 9:22
  • yes its the right one i am updating the select list and if i check the HTML i've got the new options in the list - but in the "overlayed" div for the select it wasn't updated. and yes i could parallel also update those divs but that should not been needed i think – Proximate May 26 at 9:27
  • Oh, is this a standard HTML select, or are you using ChosenJS (The library Joomla uses for fancy selects that includes a search feature) – Lodder May 26 at 10:05
  • i've included the created HTML AFTER ajax call added my options to the list. As you can see the options are set in the list. i need a way to "refresh" the form element after adding. to get the options "selectable" – Proximate May 26 at 10:49
  • 1
    You should be able to trigger an update for ChosenJS using: $('#jform_identificator').trigger("chosen:updated"); – Lodder May 26 at 13:52
2

If you're using ChosenJS, which is the fancy select library that Joomla 3.x uses, then you'll need to manually instruct it to update the list, because it doesn't use any observers by default.

You can do this by using the following:

jQuery('#jform_identificator').trigger("chosen:updated");
| improve this answer | |
  • i had to use the old command jQuery('#jform_identificator').trigger("liszt:updated"); but it was the solution. – Proximate May 27 at 12:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.