Chris
Chris

Reputation: 8826

Jquery UI Datepicker

I'd like to change the Default altFormat, but I can't seem to get it to work.

$("#myFav").datepicker({ dateFormat: 'yy-mm-dd' });
$("#myFav").datepicker('option', 'dateFormat', 'yy-mm-dd');

I thought altFormat would work just the same?

Upvotes: 0

Views: 1413

Answers (3)

roberthuttinger
roberthuttinger

Reputation: 1194

dateFormat set the date of the input that datepicker was called on, use altFormat and altField if you want to set the value of a seperate field (a hidden field that actually get sent to database, or is shared somehow by the application)

This code worked for me:

[IN HTML]

<label for="display_date">Display/Start Date</label><br />

<input type="text" class="dateStart" name="display_date" value="" /><br />

<label for="display_date_end">End Date</label><br />

<input type="text" class="dateEnd" name="display_date_end" value="" /><br />

[IN JAVASCRIPT INCLUDE]

// set the datePicker on the start and end fields

$('input.dateStart').datepicker({dateFormat:"yy-mm-dd", changeYear: true});

$('input.dateEnd').datepicker({

dateFormat:"yy-mm-dd",

changeYear: true,

beforeShow: function(){

var value = $(this).siblings('.dateStart').val();

$(this).datepicker('option', 'minDate', value);

}

});

bo huttinger

Upvotes: 0

jao
jao

Reputation: 18610

This changes the dateformat in my application:

$("#startdate").datepicker({dateFormat: 'dd-mm-yy'});

Upvotes: 0

kgiannakakis
kgiannakakis

Reputation: 104168

Have you tried what the documentation says:

$('.selector').datepicker({ altFormat: 'yy-mm-dd' });

or

$('.selector').datepicker('option', 'altFormat', 'yy-mm-dd');

For both the dateFormat and the altFormat:

$('.selector').datepicker({ dateFormat: 'yy-mm-dd', altFormat: 'yy-mm-dd' });

Upvotes: 1

Related Questions