rails form helper empty validation

Jamesla

Hi I am new to rails and have the following rails form, which works fine.

<%= form_for :user, url: users_path do |f| %>
<p>
<%= f.text_field :email, :placeholder=>'first name' %>
<%= f.text_field :email, :placeholder=>'last name' %>
<%= f.email_field :email, :placeholder=>'email address' %>
<%= f.password_field :password, :placeholder=>'password' %>
<%= f.password_field :password2, :placeholder=>'password2' %>
</p>
<%= f.submit 'Sign up!', :class=>'btn-custom btn-submit' %>
<% end %>

On the email textbox there is some client side validation built into it which will not submit the form and highlight the field if it detects a string that isn't the format of an email address.

For some reason the built in form validation doesn't check whether the text fields are empty. Is there a rails way to make it check that?

I understand that I could do it with jquery and will do it that way if there is no other way but it seems silly to have 2 separate forms of validation code.

fyi I also have validation on my model.

Muntasim

use this:

<%= f.email_field :email, :required => true, :pattern => '[^@]+@[^@]+\.[a-zA-Z]{2,6}',  :placeholder=>'email address' %>

Moreover:

you have these:

<%= f.text_field :email, :placeholder=>'first name' %>
<%= f.text_field :email, :placeholder=>'last name' %>

I guess it should be

<%= f.text_field :first_name, :placeholder=>'first name' %>
<%= f.text_field :last_name, :placeholder=>'last name' %>

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Ruby on Rails 4 - Form helper not passing a params hash to controller

분류에서Dev

Rails Action View Form Helper pass options hash to create element

분류에서Dev

Write rules in jquery-validation for Rails form

분류에서Dev

Validation in custom view helper

분류에서Dev

Javascript form validation part to check the empty data field is not working

분류에서Dev

form for helper bad collection

분류에서Dev

Rails Form Helper에 대한 좋은 API 문서가 있습니까?

분류에서Dev

Rails helper form_for ()는 url 매개 변수를 무시합니다.

분류에서Dev

First argument in form cannot contain nil or be empty in rails 4

분류에서Dev

Rails Render Partial in Helper

분류에서Dev

Prestashop helper form 'file' type

분류에서Dev

맞춤형 Rails * _for helper?

분류에서Dev

No Method Error // Helper // Rails 3

분류에서Dev

Instance variable in Rails helper not set

분류에서Dev

Rails에서 helper 및 helper_spec 작성

분류에서Dev

Jquery Form Validation

분류에서Dev

Form validation Jquery no error

분류에서Dev

jQuery validation not working with that form

분류에서Dev

Java Script form validation

분류에서Dev

html form validation with javascript

분류에서Dev

form_validation CodeIgniter

분류에서Dev

Rails models validation on update

분류에서Dev

Rails form_helper 태그를 html에 추가하려면 어떻게해야합니까?

분류에서Dev

Rails Helper : 현재 이벤트

분류에서Dev

How to include a helper method in a deep class with rails?

분류에서Dev

Javascript form validation, onblur validation and submitting

분류에서Dev

Using PHP form validation on jQuery form submission

분류에서Dev

form validation using java script

분류에서Dev

Proper form validation (PHP/MySql)