How can I get the CSV import to convert the user-provided label into the ID value?
How can I get the CSV import to convert the user-provided label into the ID value?
Very similar to https://datatables.net/forums/discussion/67056/import-csv-convert-code-to-id-using-table-ajax-json
I have a CSV with the following structure:
Name,Organisation
IME,Organisation 1
The value Organisation is a select field, with a number of options provided in the initial JSON load, with the options
key:
....
"options": {
"modbusManufacturers.organisation": [
{
"value": 1,
"label": "Organisation 1"
},
{
"value": 10,
"label": "Organisation 10"
},
{
"value": 100,
"label": "Organisation 100"
},
...
But when I submit the CSV it is setting the field value to Organisation 1
and the field does not seem to convert it to an integer ID, it silently discards it because it's not a valid value.
How can I get the ID from the user-provided label using the already-populated options in the field?
Thanks,
Tim
This question has an accepted answers - jump to answer
Answers
The best I've done is to get it from the node element
select
option
s but that really doesn't feel right:The problem is that "Organisation 1" is not a value in the list of options - it is a label. Editor can't select values based on the value - it does it on the value, so I think your workaround is probably correct at the moment.
Allan
Thanks.
I've gone with the slightly more elegant solution of storing the initial load data and using that
I think the best solution would be for Editor to select values by label in this situation - although I understand that has edge cases when it's a select with numbers + the IDs don't line up.
The middle ground would be a
field.options()
method so I wouldn't have to get them from the initial load.