standalone editor with multiple and values
standalone editor with multiple and values
He everyone!
I'm using the standalone editor with a select2. I populate the select by using the editor.field().update();
and initiate the editor using the same structure as in the examples with an <dd data-editor-field="protocol">TCP</dd>
.
But in the examples the value of the select is always the same as the option. In my case i need the id's of multiple options. But select2 doesn't understand this so when i open the editor the select-box doesn't show the currently selected options.
Is there a way to use the field().update() to set the currently selected options? I was thinking maybe i could do something like this: <dd data-editor-field="protocol" data-selected="[123,26,53,25]">some text</dd>
and then use field().update() to get the selected options and show them in the select2.
Thanks!
Wouter
This question has an accepted answers - jump to answer
Answers
No - the
update()
method is used only to set the options - not the selected values. Thefield().val()
method can be used to select the options that have been populated in the list.Are you calling the
update()
method when the Editor form is open, or at some time after theedit()
method is called?Allan
Hi Allen,
Thank you! I managed to set the value an even multiple values. It's behaving a bit buggy so i need to go over the code a few times but that brings me a big step closer!
wouter can I ask how you manage it ?
I face this problem too.
He Ahjamshidi,
I'm still working on it, but in essence it's this; i use the same page structure as in the examples with dd and dt:
then i have a function that read the data from the database using a jquery ajax call:
notice the id that is being read from the data-editor-id atribute and more important, notice that i set an extra data atribute called "selected" on field that is being used as options. that one is important because in my case i have two options, "yes" and "no", but they are stored as 1 or 0. So i want the form to display "yes" or "no" but also need the value and store that in the data-selected atribute. If you have multiple you can add it in the form of an array ["1","2","3","4"] (not sure, but think you need the quotes).
anyways, this function is called when the page is ready. so the form contains the initial record from the database.
then i initiate the editor, nothing special here:
then i watch for the editor being opened, if it is opened i read the value from the data atribute and then set the option to that value. so this takes care of the selected options in the editor.
and then when ready editing the data in the form needs to refresh. i do this by calling the same function from earlier. not the cleanest way but works perfect:
i use and inline editor which i open with this:
for another page where the option contains a long list that is being loaded from the database. this is done by loading the data from the database using an ajax request, and sending that to the option using update() and then setting the value, the same way using the val().
does that help you?