Client_side_validations gem与jquery模态视图中的formtastic不起作用
我正在尝试获取client_side_validations gem以在jquery模式视图中validation我的表单,但validation没有发生(至少在错误未显示为内联的情况下)。
我也使用了formtastic gem,所以我已经安装了client_side_validations和client_side_validations-formtastic gems来进行formtastic支持。
注意:我在app / views / layouts / application.html.erb中包含rails.validations javascript
这是我的代码:
应用程序/视图/家/ index.html.erb:
$(document).on("click", "btn-signup", function trans() { Modal.prototype.hideWithTransition = function(){ $("#signup").fadeIn(); }; }); $('#new_user').enableClientSideValidations(); $('#new_user').on('shown', function() { $(ClientSideValidations.selectors.forms).validate(); }); $("#new_user").on("submit", function hide_form() { $("#signup").modal('hide'); });
应用程序/模型/ user.erb:
class User URI::regexp(%w(http https)), :allow_blank => true end
配置/初始化/ client_side_validations.rb:
# ClientSideValidations Initializer require 'client_side_validations/formtastic' if defined?(::Formtastic) # Uncomment to disable uniqueness validator, possible security issue # ClientSideValidations::Config.disabled_validators = [:uniqueness] # Uncomment the following block if you want each input field to have the validation messages attached. ActionView::Base.field_error_proc = Proc.new do |html_tag, instance| unless html_tag =~ /^<label/ %{#{html_tag}}.html_safe else %{#{html_tag}}.html_safe end end
任何帮助或建议将不胜感激!
试试看:
更改:
至: