altFormat not working in jQuery datepicker input field

最后都变了- 提交于 2019-11-29 16:58:17

问题


I have date field (id begin-date)

$( "#begin-date" ).datepicker({ 
  minDate: -20,
  maxDate: "+1M +10D",
  dateFormat: "yy-mm-dd",
  altFormat: "yymmdd"
});

On post, it prints the format as yy-mm-dd (2010-12-08), when it should print as yymmdd (20101208)

Any ideas of why it is not posting it properly with altFormat set?

input field rendered:

<input type="text" name="begin_date" id="begin-date" class="validate[required]" value="" />

回答1:


The altFormat option doesn't control the formatting of the input with the date picker, but the format of an alternate (usually hidden) field specified by the altField option, like this:

$("#begin-date").datepicker({ 
  minDate: -20,
  maxDate: "+1M +10D",
  dateFormat: "yy-mm-dd",
  altFormat: "yymmdd",
  altField: "#alt-date"
});

You can test it out here; what you probably want is to just put the name on that alt field and that's what'll get posted...without a name the field with the date picker won't get serialized/submitted, for example:

<input type="text" id="begin-date" class="validate[required]" />
<input type="text" id="alt-date" name="begin_date" />



回答2:


the altFormat must work with altField;

<input type="text" name="pushTime" class="datetime" id="pushTime"/> $(".datetime").datepicker({altFormat:"yy-mm-dd",altField: "#pushTime"});



来源:https://stackoverflow.com/questions/4392097/altformat-not-working-in-jquery-datepicker-input-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!