如何使用 Rails client_side_validations gem 验证 jQuery 日期选择器字段?
我试图获取一个 jQuery datepicker 实例来使用 client_side_validations 进行验证,但没有任何运气。
每当我将其包含在我的模型中时,
validates_presence_of :due_date, :message => "Please select the due date"
表单就不会提交 - 没有 JS 错误,没有来自 Rails 的日志条目。
当我从没有值的字段中移除焦点时,我确实收到了错误消息,所以我知道它至少起作用了一点。
只是不知道如何提交表单。
谢谢。
I'm trying to get a jQuery datepicker instance to validate with client_side_validations and not having any luck.
Anytime I include this in my model
validates_presence_of :due_date, :message => "Please select the due date"
The form just doesn't submit - no JS error, no log entry from Rails.
When I remove focus from the field without a value I do get the error message, so I know it's working at least a little bit.
Just can't figure out how to get the form submitting.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在我看来,CSV 在 POST 之前劫持了表单,因为它没有通过,这是有道理的。你有一个 :validate => 吗? true 字段本身,并且您是否使用回调来生成消息?因为如果没有它们,CSV 似乎会默默地拒绝 POST。另外,想一想,我在选择框和 CSV 上也遇到过类似的问题,无法生成“field_with_errors”。另外,日期选择器 JS 可能与 CSV 冲突。
Seems to me CSV is hijacking the form before POST, because it doesn't pass, which makes sense. Do you have a :validate => true on the field itself, and are you using callbacks to generate a message? Because without them, it seems CSV will just reject the POST silently. Also, thinking about it, I've had a similar problem with select boxes and CSV, where no "field_with_errors" can be generated. Also, it's possible that the datepicker JS is conflicting with CSV.