html5_validators icon indicating copy to clipboard operation
html5_validators copied to clipboard

"length" validation should add "required" attribute automatically

Open kv109 opened this issue 9 years ago • 4 comments

Hi!

I've noticed that

validates :first_name, length: { minimum: 2, maximum: 50 }

translates to

<input maxlength="50" minlength="2" size="50" type="text">

To be 100% accurate with actual model validation, it should translate to
<input required="required" maxlength="50" minlength="2" size="50" type="text">

If you agree, I could prepare a pull request with that, are you interested?

kv109 avatar Nov 05 '15 12:11 kv109

@kv109 Ah, yes. I agree. Are you still willing to work on a PR?

amatsuda avatar Jan 05 '16 15:01 amatsuda

@amatsuda Not really. I wanted you to merge my another PR first (you just did). But I have something different. On my own fork I did simple handling of :if and :unless options. Code is messy, since it was written just for my team, but I could rewrite it. It was helpful for us since we have a lot of validations with simple :if and :unless conditions. Let me know if you would be interested.

kv109 avatar Jan 05 '16 15:01 kv109

what is the state of this? :thinking:

Ana06 avatar Apr 24 '19 15:04 Ana06

I haven't installed this gem and just reading through issues before I do.

Unfortunately have to disagree on this...it's a narrow/opinionated use case. If you want both required and string length validation, they should be separate (separate/distinct use cases).

EdSF avatar Jun 20 '19 16:06 EdSF