-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added optional Select input binding #847
Conversation
Thank you for your kind words, it's always great to see Udash successfully used outside of our org :) Regarding the PR, I'm not yet convinced that it improves upon the current API so much - I think I may be missing some use case. Let's assume: val fruitProperty = Property[Option[Fruit]](None) Then the current Select(
fruitProperty, Seq(Apple, Orange, Banana).map(_.option).prepended(None).toSeqProperty
)(maybeFruit => maybeFruit.mapOr("Label no value", _.name)) and the new, utility one: Select.optional(
fruitProperty, Seq(Apple, Orange, Banana).toSeqProperty, labelNoValue = "Label no value"
)(_.name) Sure, we get to avoid boxing in |
Hi @ddworak , my example it's no more complex from what you wrote, the need of adding the <select>
<option value="0">Label no value</option>
<option value="1">Apple</option>
...
</select> but you won't be able to use HTML5 required since "Label no value" has with my implementation you'll get: <select>
<option value="">Label no value</option>
<option value="0">Apple</option>
...
</select> so if "Label no value" is selected and the element is required the validation fails as expected. But I agree that we could just change the underlying implementation. val el = option(value := idx.toString, label(opt)).render if If you like that idea I can update the PR with the implementation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh now I see. I think you were right to create a separate method then - it's a different behaviour - we just need more clarity for the user as to what the differences are.
core/.js/src/main/scala/io/udash/bindings/inputs/SelectBinding.scala
Outdated
Show resolved
Hide resolved
core/.js/src/main/scala/io/udash/bindings/inputs/SelectBinding.scala
Outdated
Show resolved
Hide resolved
core/.js/src/main/scala/io/udash/bindings/inputs/SelectBinding.scala
Outdated
Show resolved
Hide resolved
Thank you for reviewing my code. I did the changes you suggested and added a test case. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for these improvements. I've left 2 minor comments and I think we'll be ready to ship after that.
Done, when you think it could be available on maven central? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thank you for nice contribution :) I'll push the M17 tag right after merge, so it'll be available as soon as the central processes the artifact, usually a couple hours.
First of all thank you very much for the great product. I'm a very happy udash user! And using it extensivly on my open source project https://github.com/Insubric/box
For my projects I'm using quite a lot the native HTML5 form validation, an in general with udash it works smoothly, I just come across a minor limitation on the select element, using
required
on the select element with the current implementation does not trigger any validation and we have no way to put anull
option, but there are use cases where this is needed.For reference see MDN select required documentation https://developer.mozilla.org/en-US/docs/Web/HTML/Element/select#attr-required.
In order to overcome this limitation my proposition is to add a
optional
method onio.udash.bindings.inputs.Select
with that signature:basically is the same of the
apply
just the selectedItem is optional and we need a label when no value is selected.The usage is pretty straightforward.
Thanks
Andrea