简体   繁体   English

Bootstrap Datepicker:格式更改为默认值

[英]Bootstrap datepicker: The format is changed to default

I want to have a datepicker with the format dd.mm.yyyy . 我想要一个日期选择器,其格式为dd.mm.yyyy The inputField looks like this: inputField看起来像这样:

<h:inputText value="#{eventController.startdateAgenda}" styleClass="datepicker form-control" id="id_startdate" converterMessage="Example: 26.05.2015" >
    <f:convertDateTime pattern="dd.MM.yyyy"/>
</h:inputText>

The JavaScript part: JavaScript部分:

$(document).ready(function () {
    $('.datepicker').datepicker({
                format: 'dd.mm.yyyy',
                autoclose: true
    });
});

That works for the first time. 那是第一次。 But when I clear and fill the inputText, the date will be formatted "mm/dd/yyyy" . 但是当我清除并填充inputText时,日期将被格式化为"mm/dd/yyyy"

Clicking on this commandLink fills the field: 单击此命令链接可填充字段:

<h:commandLink>
    <f:ajax onevent="function(data){if (data.status === 'success'){$('.datepicker').datepicker(); setDateFormat(); }}" listener="#{eventController.editAgendaEntry(a)}" execute="@this" render=":agendaData agendaTable"/>
    <span id="pen" class="add-on glyphicon glyphicon-pencil" aria-hidden="true" align="right"></span>
</h:commandLink>

How can I fix it? 我该如何解决?

UPDATE: When I refresh the page, the format is right again. 更新:当我刷新页面时,格式再次正确。

I solved it now by adding this 我现在通过添加这个解决了

String js = "$('.datepicker').datepicker({format: 'dd.mm.yyyy', autoclose: true});"; 
RequestContext.getCurrentInstance().execute(js);

to every validator method and submit method. 每个验证器方法和提交方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM