Closed jeremyfelt closed 7 years ago
This fix still leaves multi selects not being selected when editing a shortcode. The short term fix for me was to just ensure that I don't have comma's in my values and split on comma instead of an empty split.
<option value="{{ option.value }}" <# if ( ! _.isEmpty( _.filter( _.isArray( data.value ) ? data.value : data.value.split(","), function(val) { return val === option.value; } ) ) ) { print('selected'); } #>>{{ option.label }}</option>
I tried to reproduce the issue @cowanr was having and I think can reproduce. I think they are correct that simply calling .split(',')
will work instead.
Also I think we can simplify this code by using _.contains
. I'm going to open a new PR with these additions.
Closing this PR in favor of #745.
During work in #707 to improve support for multi-select fields, handling of comma separated strings was removed as it may have been confusing if an option value had commas in it.
See 9894162ab8bf02941e9611766d5cc3d63d337e96
After this change, string values for single select elements are filtered as if they were arrays. This causes only the first character of a string to be compared to the select value. This in turn results in all select fields set to first option because nothing is seen as selected.
We can accept arrays, but also
split()
with no separator to turn strings into an array so that everything is parsed the same.