Passing label & value to update method for a field
Passing label & value to update method for a field
paulhickman
Posts: 21Questions: 1Answers: 0
In the documentation for the update method you have the example:
[code]
editor.add( {
"type": "select",
"label": "Title:",
"name": "title",
"ipOpts": [
{ "label": "Mr", "value": "Mr" },
{ "label": "Ms", "value": "Ms" },
{ "label": "Mrs", "value": "Mrs" },
{ "label": "Miss", "value": "Miss" },
{ "label": "Dr", "value": "Dr" }
]
} );
editor.field('title').update( [
"Mr", "Ms", "Mrs", "Miss", "Dr"
] );
[/code]
What would you put in the call to update() if the label and values were different?
[code]
editor.add( {
"type": "select",
"label": "Title:",
"name": "title",
"ipOpts": [
{ "label": "Mr", "value": "Mr" },
{ "label": "Ms", "value": "Ms" },
{ "label": "Mrs", "value": "Mrs" },
{ "label": "Miss", "value": "Miss" },
{ "label": "Dr", "value": "Dr" }
]
} );
editor.field('title').update( [
"Mr", "Ms", "Mrs", "Miss", "Dr"
] );
[/code]
What would you put in the call to update() if the label and values were different?
This discussion has been closed.
Replies
In the `select` field type, you can pass in:
- An array of objects, where the objects have `label` and `value` properties
- An array of values (strings, integers)
If an array of values is passed in, the value is used for both the label and value, if an object is passed in, each is used as appropriate. You can actually mix the two types together if you wanted as well...
In future I'll add the ability to pass in an array of functions or just a function that returns an array.
So that example is misleading in that the update actually just sets exactly the same options as are already present! However, it should work correctly.
> What would you put in the call to update() if the label and values were different?
Just to clarify, the `update` call will completely replace the values that are already present. They have no bearing on the new values.
Regards,
Allan
[code]
editor.field('title').update( [
{ label: "Mr", value: 0}, { label:"Ms", value: 1}
] );
[/code]
Allan
I understood I could use it in ipOpts. What wasn't clear from the example in the documentation was that the update() method offered the same flexibility.
Thanks,
Allan