-
Notifications
You must be signed in to change notification settings - Fork 630
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
HTML5 range input support #417
Comments
I'm waiting for this feature and I want to contribute. How can I help implementing this? |
Hi, the simple answer is fork and patch! The slightly longer answer is that we're doing a bunch of refactoring in the v2 branch before I push ahead on any new features. There's stacks of value in someone figuring this out though — coming up with the test cases and checking the DSL fits, etc. Get started and we'll find a way to merge it in! |
Ok, so I've made the fork and created that input. It creates generic rails input: range_field. It also uses reflection for range validation. I tested it with the following model:
It works and generates allowed ranges of values for the input as following for those examples:
I'm not however convinced, that this input is any useful, these are just sliders without legend, so tell me what you think. The code is here |
Looks like a great start. If you did an ||= on
And :in is a lot like :collection, so it could be an option in the top namespace, allowing this:
In regards to markup, I think the right elements are there, but there's a few more attributes we could nail. There's also Finally, to smash it out of the park, I'm wondering if we could automatically build a :hint (if one is not set, not false, not already translated, etc) which describes the allowed values:
This would hep users with clients that don't do much with the new elements. You certainly don't have to do all that, but this is the place for the brainstorming and discussion :) |
Oh, I see your point and I'll provide that |
Tested new features with |
Brilliant! Test coverage would be great, and we can treat the hint stuff as a separate issue. |
Ok, I'll write some tests too, but there's one more thing. I'm using validation_reflection itself when it's defined, because I've not seen anything other than |
reflect_on_validations_for seems to be what we're using elsewhere in the code, so you seem to be using the established patterns. I thought validation reflection was kind of "solved" in Rails 3 and didn't require a plugin any more, but the comments still hint at it, so who knows. |
That's tested now and with this code I can implement some helper for validation that specifies range (and step?) options. It could be used in number_field_tag and similar. |
I've made that helper and used it for |
How's refactoring by now? Are you close to the finish? I think this can be pulled without conflicts and gives numeric fields better support. |
farnoy, justinfrench are doing another refactoring. please wait a little more. |
Ok, refactor branch is pretty smooth. I'll be merging into master pretty soon, so now is as good a time as any to get this in! The refactor branch is a pretty major diversion from v2, (class based inputs, not modules) so you may have to re-implement, but you should be able to copy the specs straight over and the new code base is ultra clean. If you're out of time, send me a pull request against v2 and I'll try to port it over myself. If you want help groking the new code, sing out! |
I will try to prepare it for the |
Awesome! |
This has been (mostly) implemented and merged into master. Remaining issues have separate issues created, so closing this! |
Leverage validation reflection for min and max attributes?
The text was updated successfully, but these errors were encountered: