views:

352

answers:

1

Hi

I'm having a problem trying to format the output on the jQuery UI datepicker.

I want the dateformat to be the 'ISO 8601' format, like explained here:

http://jqueryui.com/demos/datepicker/#date-formats

This is what my code looks like:

$.datepicker.setDefaults($.datepicker.regional['nl']);
$('.datepicker').datepicker('option', {dateFormat: 'yy-mm-dd' });

Can someone help and advice plz?

Thx in advance! I really trust this community for providing a quick and great answer! :)

A: 

Your option setter format is just a bit off, try this:

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

See the options pane on that page for how to set each one in this way

when doing it globally before creating a picker, do this:

$.datepicker.setDefaults($.datepicker.regional['nl']); 
$.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });
//Later..
$('.datepicker').datepicker();

Also, make sure to include your regional file, or the $.datepicker.regional['nl'] doesn't mean anything, this needs to be included before trying to setDefaults to your regional: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/

Nick Craver
I thried that , It's not working. I'm following this step:$('#datepicker').datepicker('option', {dateFormat: $(this).val()});in the source view of the demo link I gave you
Sam Vloeberghs
@Sam - is the datepicker open when doing this? This only affects a created datepicker on `$('.datepicker')`, if you're doing this on page init before creating one, do: `$.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });` (after your current setDefaults call)
Nick Craver
k thx! This did it :$.datepicker.setDefaults($.datepicker.regional['nl']);$.datepicker.setDefaults({ dateFormat: 'yy-mm-dd' });$('.datepicker').datepicker();
Sam Vloeberghs
@Sam - Excellent, +1 and welcome to SO, you can now vote on things :) I'll edit this answer to the next person having your problem find the solution faster
Nick Craver
Christ.. The regional setting still doesn't work :(
Sam Vloeberghs
@Sam - What's it doing?
Nick Craver
not changing the regional from 'en' ( I believe ) to 'nl'
Sam Vloeberghs
got it! Best to mention in your final answer that people still have to include the regional files for datepicker. Located here: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/
Sam Vloeberghs
@Sam - Make sure you're including the regional file for nl before running that: http://jquery-ui.googlecode.com/svn/trunk/ui/i18n/jquery.ui.datepicker-nl.js
Nick Craver