使用datetimepicker在rails 4中重新加载页面后的日期格式更改 [英] Date format changing after reload page in rails 4 using datetimepicker

查看:365
本文介绍了使用datetimepicker在rails 4中重新加载页面后的日期格式更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



当我进入主页时:
http://leszczyna.wzks.uj.edu.pl/12_stolarski/events_for_seniors/
并点击第二个字段在搜索和选择的东西,出现的日期格式是' dd-mm-yyyy '。



但是当我点击左上角的Wydarzenia dlaseniorów日期格式正在更改为 dd / mm / yyyy
我注意到区域设置显示在URL中,但不知道是否影响了该行为。



此外,当我刷新页面后



什么可以导致该输入的奇怪行为?



编辑



我的观点代码:

 < div class =form-group> 
< label class =sr-onlyfor =date> Email< / label>
<%= text_field_tag:date,
params [:date],
placeholder:'Kliknij,abywybraćdatę',
class:'form-control input-lg date ',
:data => {
提供:'datepicker'
}
%>
< / div>

我的javascript:

  / *搜索日期* / 
if($('body.homepage')。length){
$('。date')。datepicker({
'language':pl,
'todayHighlight':true,
'format':'dd-mm-yyyy',
'autoclose':true
})
}


解决方案

$ c> turbolinks ,关闭左上角Wydarzenia dlaseniorów链接的 turbolinks 。在标题中,您的链接位于带有 navbar-header 类的div下。对于该div元素,添加 data-no-turbolink ,示例如下

  < div class =navbar-headerdata-no-turbolink> 

这将解决您的问题!





在您的js文件中,加载像这样的javascript

  ready = function(){

/ *搜索日期* /
if($('body.homepage')。length){
$ '.date')。datepicker({
'language':pl,
'todayHighlight':true,
'format':'dd-mm-yyyy',
'autoclose':true
});
}
}
$(document).ready(ready);
$(document).on('page:load',ready);

这是最好的解决方案。



希望这有帮助!


I've noticed something strange in my app.

When I enter to the main page here: http://leszczyna.wzks.uj.edu.pl/12_stolarski/events_for_seniors/ and click on the second field in search and pick something, the date format appearing is 'dd-mm-yyyy'.

But when I click in the top left-hand corner 'Wydarzenia dla seniorów' date format is changing to 'dd/mm/yyyy'. I've noticed that locale is appearing in URL but have no idea if it has impact on that behavior.

What is more, when I refresh page after that, date format comes to the beginning.

What can cause that strange behavior of that input?

EDIT

Code from my view:

<div class="form-group">
      <label class="sr-only" for="date">Email</label>
      <%= text_field_tag :date,
                         params[:date],
                         placeholder: 'Kliknij, aby wybrać datę',
                         class: 'form-control input-lg date',
                         :data => {
                                 provide: 'datepicker'
                         }
      %>
    </div>

And my javascript:

    /* Search date */
if ($('body.homepage').length) {
    $('.date').datepicker({
        'language': "pl",
        'todayHighlight': true,
        'format': 'dd-mm-yyyy',
        'autoclose': true
    })
}

解决方案

It's happening due to turbolinks, turn off turbolinks for the top left-hand corner 'Wydarzenia dla seniorów' link. In the header your link is present under a div with navbar-header class. To that div element add data-no-turbolink, example below

<div class="navbar-header" data-no-turbolink>

This will resolve your problem!

or

In your js file, load javascript like this

ready = function(){

  /* Search date */
  if ($('body.homepage').length) {
    $('.date').datepicker({
        'language': "pl",
        'todayHighlight': true,
        'format': 'dd-mm-yyyy',
        'autoclose': true
    });
  }  
}
$(document).ready(ready);
$(document).on('page:load', ready);

This is the best solution.

Hope this helps!

这篇关于使用datetimepicker在rails 4中重新加载页面后的日期格式更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆