Achot: Chosen (v1.6.2)

Beitrag lesen

Hallo,

ich verwende für meine select-Liste folgendes Script: https://harvesthq.github.io/chosen/options.html

Nun möchte ich gerne nach dem ich per Ajax etwas hinzugefügt habe

$("#location option:last").after($('<option value="'+ data.id +'" selected>'+ data.name +'</option>'));

dass dieser Eintrag direkt ausgewählt ist. Das selected greift, dieses sehe ich im Quelltext, allerdings wird mir im Dropdown noch immer Bitte wählen ... angezeigt.

Kennt sich von euch jemand mit Chosen aus?

Es gibt zwar ein **Updating Chosen Dynamically*×

If you need to update the options in your select field and want Chosen to pick up the changes, you'll need to trigger the "chosen:updated" event on the field. Chosen will re-build itself based on the updated content.

dieser wirkt bei mir irgendwie nicht

$("#location option:last").after($('<option value="'+ data.id +'" selected>'+ data.name +'</option>'));
$("#location").trigger("chosen:updated");