如何从 clockpicker 获取值并将其传递到我的表单 f.date_field?
How to get value from clockpicker and pass it to my form f.date_field?
我正在构建一个需要用户输入 event.I 的日期和小时的应用程序,我正在使用 form_for 帮助程序并在 f.submit.I 能够接受之前获取值日期通过 f.date_field 正确地为您提供了 minicalendar 的构建,我正在使用 bootstrap 时钟选择器来获取 hour.Here 是 problem.I 想要获取小时并将其连接到 f.date_field 因为它需要默认时间 00:00:00 UTC 但我不知道该怎么做 it.I 我是 Javascript 的初学者。任何帮助将不胜感激。这是我的代码:
html 和一些 ruby
<div class="input-group clockpicker" data-
placement="right" data-align="top" data-
autoclose="true">
<input id ="time1" type="text" class="form-control"
value="ώρα..">
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
<br>
<div id="newgame">
<%= f.submit "New Game" %>
</div>
这是我的时钟选择器脚本
<script type="text/javascript" src="dist/bootstrap-
clockpicker.min.js"></script>
<script type="text/javascript">
$('.clockpicker').clockpicker();
</script>
我找到了答案,一个不是 JS 的方法是添加到输入
... name='游戏[时间] ..>
然后像这样把这个值传给控制器
#get time from clock and concatenate it with date to start_time
date = params['game']['start_time']
time = params['game']['time']
@game.start_time = Time.parse("#{date} #{time}") + 3.hours
+3.hours 是因为它花费的时间与我的时区不同,我不得不调整它。
我正在构建一个需要用户输入 event.I 的日期和小时的应用程序,我正在使用 form_for 帮助程序并在 f.submit.I 能够接受之前获取值日期通过 f.date_field 正确地为您提供了 minicalendar 的构建,我正在使用 bootstrap 时钟选择器来获取 hour.Here 是 problem.I 想要获取小时并将其连接到 f.date_field 因为它需要默认时间 00:00:00 UTC 但我不知道该怎么做 it.I 我是 Javascript 的初学者。任何帮助将不胜感激。这是我的代码:
html 和一些 ruby
<div class="input-group clockpicker" data-
placement="right" data-align="top" data-
autoclose="true">
<input id ="time1" type="text" class="form-control"
value="ώρα..">
<span class="input-group-addon">
<span class="glyphicon glyphicon-time"></span>
</span>
</div>
<br>
<div id="newgame">
<%= f.submit "New Game" %>
</div>
这是我的时钟选择器脚本
<script type="text/javascript" src="dist/bootstrap-
clockpicker.min.js"></script>
<script type="text/javascript">
$('.clockpicker').clockpicker();
</script>
我找到了答案,一个不是 JS 的方法是添加到输入 ... name='游戏[时间] ..>
然后像这样把这个值传给控制器
#get time from clock and concatenate it with date to start_time
date = params['game']['start_time']
time = params['game']['time']
@game.start_time = Time.parse("#{date} #{time}") + 3.hours
+3.hours 是因为它花费的时间与我的时区不同,我不得不调整它。