Skip to content
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

Add abide validation helpers #100

Open
dsandstrom opened this issue Apr 29, 2015 · 1 comment
Open

Add abide validation helpers #100

dsandstrom opened this issue Apr 29, 2015 · 1 comment

Comments

@dsandstrom
Copy link
Collaborator

Reference: http://foundation.zurb.com/docs/components/abide.html

If a field has a required attribute, the form should get a data-abide attribute and a <small class="error">required</small> should be added below the field. The error message should be able to be edited with a field option.

@jlaw90
Copy link

jlaw90 commented Nov 23, 2015

I agree that abide validation would be great, I don't think the framework should automatically add the data-abide attribute to the form based on specific attributes on controls however.

If form_for had an option to enable abide validation which subsequently added the error tags to controls then that would work great in all scenarios. The main problem here would be how to get a generalised error message depending on the validation that failed.

I propose something like the following should be flexible enough for most cases:

= form_for(@user, abide: true) do |f|
  = f.text_field :username, required: true, pattern: '[a-zA-Z]+', error: 'Please enter your username'
  = f.password_field :password, required: true, error: 'Password is required'

Which would generate the following html:

<form class="new_user" action="/users/new" data-abide accept-charset="UTF-8" method="post">
  <div class="user-username-field">
    <label for="user_username">Username <small>required</small>
      <input type="text" name="user[username]" id="user_email" required pattern="[a-zA-Z]+">
    </label>
    <small class="error">Please enter your username</error>
  </div>
  <div class="user-password-field">
    <label>Password <small>required</small>
      <input type="password" name="user[password]" id="user_password" required>
    </label>
    <small class="error">Password is required</small>
  </div>
</form>

It would be even better if the code generating the fields could automatically add pattern and required attributes based on rails validations but that would probably be a bit more difficult!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants