Closed amayr666 closed 6 years ago
Returning an array even if there's only 1 element is the behavior that I'm expecting and is by design. If it's returning an array every time, then at least I know that I can use a repeat without doing some extra logic to check if it's a single object or an array. This behavior is especially useful when the select is populated dynamically and you don't know how many could be in.
I think you got me wrong. If I specify multiple = "true", then Id 100% expect getting an array in the selected-value.bind. But if I don't specify multiple at all, I'd expect only one element since I have already decided that I don't want to receive an array, no matter how many selectOptions the select has. Don't you think so?
That is a good assumption, however it does currently behave with the result always showing up as an array and that can be seen in the demo page (with exception of the first sample which is a String Collection).
Looking at the code, I can see why since I use a findItems() function that always return an array. This could possibly be changed to detect that when it's not a multiple
, then only return the first object of that findItems
array (since it will always include only 1 anyway).
You can submit a PR or wait until I get time in a few days. Also since this would impact users, I would probably make it a semver minor
and so that would become 1.1.0
.
I pushed version 1.1.0
on NPM that should fix what you reported. As mentioned earlier, I made a semver minor
because that might affect other users. Thanks
Thank you, we really appreciate your good work :)
I found some strange behaviour, if I use the select as following:
My bound select-value "companyData.address.country" is an array with 1 element, even if no "multiple=true" is set. Therefore I have to use a ugly hack to always fetch the first element from the array before i continue using the companyData. Is this an expected behaviour?
Best regards, Alex