Rails:Datimepicker 字段中始终为空
我正在使用 datimepicker (来自:http://trentrichardson.com/examples/timepicker/)但是我无法将纠察队日期-时间组合保存到数据库中。它忽略值并始终将其保存为空。
我的 Application.js 文件中有这个,
ok $("#child_dob").datepicker({changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy", altFormat: 'yy-mm-dd' });
notOk $("#announcement_date").datetimepicker({ampm: true, altFormat: 'yy-mm-dd hh:mm:ss', dateFormat: "mm-dd-yy", timeFormat: 'hh:mm tt'});
因此 dob 字段上的子模型可以工作,因为它只是日期选择器,但是,使用 datetimepicker 的日期上的公告模型只会保存为空。我尝试了不同的“altFormat”和日期/时间格式,但没有成功。我知道这是可以做到的,因为我以前用过它,但现在不确定出了问题。任何指导将不胜感激。
谢谢。
环境: 轨道3.1 jQuery 1.6.2 jQueryUI 1.8.16 操作系统:狮子
I am using datimepicker (from: http://trentrichardson.com/examples/timepicker/) however I cannot save the picket date-time combo to the database. It is ignoring values and always saving it as empty.
I have this on my Application.js file
ok $("#child_dob").datepicker({changeMonth: true, changeYear: true, dateFormat: "dd-mm-yy", altFormat: 'yy-mm-dd' });
notOk $("#announcement_date").datetimepicker({ampm: true, altFormat: 'yy-mm-dd hh:mm:ss', dateFormat: "mm-dd-yy", timeFormat: 'hh:mm tt'});
So the child model on dob field works because it is just the datepicker, however, the announcement model on date with datetimepicker will only save empty. I played around with different "altFormat" and date/time format but without success. I know this can be done as I have used it before but am not sure went wrong now. Any guidance will be greatly appreciated.
Thank you.
Env:
Rails 3.1
JQuery 1.6.2
JQueryUI 1.8.16
OS: Lion
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仅当您使用“altField”时,alt 字段才重要。您可以省略“altFormat”,它应该可以正常工作。
您将“altField”设置为指向隐藏的输入来存储您的日期/时间值。如果您使用“altField”,则可以使用“altFormat”来格式化该隐藏的时间字段。如果您同时使用这两个选项,则需要将“altFieldTimeOnly”设置为 false(默认为 true)。
这应该有效:
The alt fields only matter if you're using 'altField'. You can omit 'altFormat' and it should function properly.
You set the 'altField' to point to a hidden input to store your date/time value. If you use 'altField', you then use 'altFormat' to format that hidden time field. If you are using both of those you will want to set 'altFieldTimeOnly' to false (it defaults to true).
This should work: