Rails : gem ‘rails4_client_side_validations’ to validate the forms in popup

How the gem works?

For the form you want to validate, you maintain the validations in the respective Model. The validation set in the model works for server-side validation. For client-side validation this gem actually creates the required js codes the validation you set in the model.

Solution No: 1

# Just after the form is loaded in the DOM if your gem is client_side_validations
$(new_form).enableClientSideValidations();

# Specifically for rails4_client_side_validations gem
$(new_form).enableRails4ClientSideValidations();

Solution No: 2

So, in case of popups the required js codes have not been loaded in the document yet, so you need to render the js too with the view for the popup

In my case I created a layout specific for this popup or all this type of popups. and just rendered the validator’s js

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s