How to update editor form options for both value and text?

How to update editor form options for both value and text?

WCGPR0WCGPR0 Posts: 4Questions: 3Answers: 0

Hello there!

fields = [
{
    label: "Foo Bar"
    name: "FooBar",
    type: "select"
}

I'm looking to update this dropdown dynamically, and am doing it on the on Open event,

editor.on('open', function (e, mode, action) {
   var someOptions = ['1','1','3','4'];
   editor.field('FooBar').update(someOptions);
});

However this produces the options as,

<select name="FooBar" class="form-control valid">
 <option value="1">1</option>
 <option value="1">1</option>
 <option value="3">3</option>
 <option value="4">4</option>
</select>

What I need is the following:

<select name="FooBar" class="form-control valid">
 <option value="a">1</option>
 <option value="b">1</option>
 <option value="c">3</option>
 <option value="d">4</option>
</select>

I did noticed in the documentation for fields().update() I'm able to pass in an object, but didn't see any examples of that.

Would I be able to pass in something similar to below, or is this not yet achievable using the current APIs?

! { "a" : 1, "b" : 1, "c" : 3, "d" : 4 }
or
! [ {"value": 1, "name": "a"}, {"value": 1, "name": "b"}, {"value": 3, "name": "c"}, {"value": 4, "name": "d"} ]?

This question has an accepted answers - jump to answer

Answers

This discussion has been closed.