简体   繁体   中英

How to add Javascript validations to Rails simple_form?

I want to validate some inputs on my Rails simple_form. HTML is good but not working with many InAppBrowsers.

<%= simple_form_for(:member, :url => registration_path(:member), html: { multipart: true }) do |f| %>
   <%= f.input :email, required: true, autofocus: true, label: "Adresse e-mail", placeholder: "jeanne.dupont@gmail.com" %>
<% end %>

I would like to use Javascript to do this but I don't know how to implement it without plugin.

Any ideas ? Many thanks

You can try this:

    $("#your-form-id" ).submit(function( event ) {
      if( your_validation() )
        return;
      else event.preventDefault();
    });

hope this helps.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM