forked from heartcombo/simple_form
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow validation classes on input_field
This PR is similar to this one heartcombo#1552. It allows validation classes on `input_field`. To get this work I added two configs for the Simple Form: `input_field_error_class` and `input_field_valid_class`. Once the user adds a class for these configs, the configured classes will be rendered according to the form validation. - Setup the `input_field` classes. ```ruby SimpleForm.setup do |config| config.input_field_valid_class = 'is-valid' config.input_field_error_class = 'is-invalid' end ``` - Build the form. ```erb <%= simple_form_for @Product do |f| %> <%= f.input_field :name %> <div class="form-actions"> <%= f.button :submit %> </div> <% end %> ``` - When the validation happening, the input will be rendered with the validation classes. ```HTML <-- Valid example --> <input class=" is-valid string required" type="text" value="PS4" name="product[name]" id="product_name"> <-- Invalid example --> <input class=" is-invalid string required" type="text" value="" name="product[name]" id="product_name"> ```
- Loading branch information
1 parent
102b9eb
commit fad0393
Showing
7 changed files
with
94 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters