Code Monkey home page Code Monkey logo

Comments (1)

jlaw90 avatar jlaw90 commented on July 26, 2024

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!

from foundation_rails_helper.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.