client_side_validations-simple_form icon indicating copy to clipboard operation
client_side_validations-simple_form copied to clipboard

inputs with :as => :radio_buttons are being skipped in validation

Open vitalim opened this issue 11 years ago • 21 comments

In a form I'm building using ClientSideValidations + SimpleForm (with the gem plugin) the client side validation works for all fields except the :radio_buttons. The HTML that is produced for this group is similar to the other working ones:

`

...
`

Yet when the submit button is clicked, all the other inputs get the 'error' class but the radio_buttons input does not. If I remove the :as => :radio_buttons, the client side validations works just fine.

Any idea what is causing this? Thanks!

vitalim avatar Mar 03 '13 17:03 vitalim

Radio buttons were filtered out of the parent ClientSideValidations gem but were always intended to be put back in with ClientSideValidations-SimpleForm and ClientSideValidations-Formtastic.

They are being filtered because in the regular Rails form builder there is no concept of wrapping the radio buttons in a single group so it is not possible to render the errors in a similar manner as the server will render.

However, with Formtastic and SimpleForm it does render as a group so the render function can attach to this wrapper element. For some reason I never got around to putting this functionality back in. I should prioritize it.

Thank you for bringing it to my attention.

bcardarella avatar Mar 03 '13 17:03 bcardarella

Is there a hotfix for this?

daliusg avatar Mar 13 '13 10:03 daliusg

I'm having this same problem. is there any hot fix for that?

jerryshen avatar Apr 24 '13 16:04 jerryshen

+1 for hotfix .. having a hard time implementing a reliable solution in client_side_validations-simple_form

matenia avatar May 21 '13 12:05 matenia

+1 Bug in local presense validator. $().val() from check-box return value, without considering that it must be checked.

KODerFunk avatar Jul 15 '13 14:07 KODerFunk

+1

hau avatar Jul 20 '13 09:07 hau

+1

danielballan avatar Aug 13 '13 21:08 danielballan

@bcardarella - Any chance on providing some guidance on what needs to be do to implement this fix?

alexfalkowski avatar Nov 19 '13 06:11 alexfalkowski

+1

elijahmurray avatar Feb 22 '14 01:02 elijahmurray

+1

AlecRust avatar Jan 21 '15 22:01 AlecRust

Here's a quick hack around the problem. It seems as though even though radio buttons are not processed, the gem is still sending data about the radio button validations to the browser. Type 'window.ClientSideValidations.forms' into the JS console and you'll see what gets sent down. So I wrote a bit of jQuery that checks all of my forms for radio buttons, then sees if there are any presence validations for those buttons. If so, it displays an error message. Note that in Rails, you'll need to wrap your related radio buttons into a div. Hope it helps someone. http://pastebin.com/FMzS9dBj

manishie avatar Feb 08 '15 21:02 manishie

@manishie thanks. I'm not confident to add this at the moment but this will definitely help.

tagliala avatar Feb 08 '15 21:02 tagliala

oh, I didn't mean for you to add it! It's just a quick hack I threw together to get around the problem. Thanks!

manishie avatar Feb 08 '15 21:02 manishie

@manishie sure I got you didn't mean that. I just was informing everyone that I will not do this soon. PR with proper tests are welcomed

tagliala avatar Feb 08 '15 21:02 tagliala

had this fixed?

august-9426 avatar Jan 14 '17 16:01 august-9426

@August7752 sorry for the very late reply, I've missed this notification.

This feature is not implemented and I will probably not implement this. PR with proper tests are very welcomed

@cooljl31 please use GitHub reactions to add upvotes. Other +1s are here just because there weren't github reactions at the time

tagliala avatar Feb 23 '17 16:02 tagliala

@manishie I did some experimentation and realised, that not all data is sent from server. For example radio buttons and check boxes are not present in form data attribute, regardless what validations (standard or custom) I add to them. Maybe it worked on an older version of client-side-validations?

sekrett avatar Dec 21 '18 15:12 sekrett

+1 please

jhovad avatar Aug 26 '19 21:08 jhovad

Yes validations for radio_buttons etc.. aren't in CSV Hash, because SimpleForm doesn't use (anymore) FormBuilder's methods (which CSV overrides to build validation hash) to to build these special inputs. But it uses ActionView:Helpers::Tags for these now, so there is some more overriding needed. I am looking into it.. wan't to make it work.

MichalRemis avatar Apr 17 '20 16:04 MichalRemis

I implemented missing validations into CSV SimpleForm (checkboxes, radios, date_time selects). Meanwhile, until it will be merged into main gem you may use it from my repo.

gem 'client_side_validations-simple_form', github: 'MichalRemis/client_side_validations-simple_form'

It works only when JS is added via sprockets

//= require rails.validations
//= require rails.validations.simple_form.bootstrap4

because I don't provide npm package.

MichalRemis avatar Jun 03 '20 16:06 MichalRemis

because I don't provide npm package.

it is possible to point npm packages to github repos:

In package.json:

    "package": "user/repo#branch",

tagliala avatar Jun 03 '20 16:06 tagliala