Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

altFormat not working in jQuery datepicker input field

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="" />
like image 757
Brad Avatar asked Dec 08 '10 20:12

Brad


2 Answers

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" />
like image 132
Nick Craver Avatar answered Oct 01 '22 18:10

Nick Craver


the altFormat must work with altField;

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

like image 28
user2231487 Avatar answered Oct 01 '22 17:10

user2231487