NOTE / Ruby-On-Rails

Ruby Jquery Form Validation Plugin


在這使用的是bootstrap-validator是輸入一個去做驗證而不是整個一起送出後才驗證效果會比較好
請先下載bootstrap-validator
放在vendor\assets\javascripts\目錄下面

//= require validator.min
<div class="form-group">
  <%= f.label :name, "姓名", :class => "control-label" %>
  <%= f.text_field :name, :class => "form-control", :required => true, :autofocus => true %>
  <div class="help-block with-errors"></div>
</div>

使用HTML5 前端資料驗證 補上:required => true

<%= f.text_field :name, :class => "form-control", :required => true, :autofocus => true %>

其實主要是加上這段讓他錯誤顯示於輸入窗正下方

<div class="help-block with-errors"></div>

使用Jquery驗證

$("form").validator();

REFERENCE / 3

Loading