9

I added a jQuery datepicker in my symfony2 form.

twig file:

$('.date').datepicker({ 
    showOn: 'button', 
    buttonImageOnly: true, 
    changeMonth: true,
    changeYear: true,
    dateFormat: 'yy-MM-dd ',
    yearRange: "-0:+1"  
});

PostType.php

$builder->add('toDate','datetime',array(
                'input' => 'datetime',
                'widget' => 'single_text',
                'format' => 'yy-MM-dd',
                'attr' => array('class' => 'date')
        ));

I tried several date formats. But I always get This value is not valid. when I submit. I tried to get the form errors, but it doesn't give any more information.

2 Answers 2

11

try something like this

$('.date').datepicker({ 
    showOn: 'button', 
    buttonImageOnly: true, 
    changeMonth: true,
    changeYear: true,
    dateFormat: 'dd-mm-yy',
    yearRange: "-0:+1"  
});

PostType.php

$builder->add('toDate','date',array(
    'widget' => 'single_text',
    'format' => 'dd-MM-yyyy',
    'attr' => array('class' => 'date')
 ))
Sign up to request clarification or add additional context in comments.

3 Comments

thats great, it works! is there a documentation for this date formats and jquery?
just to point out that this post is just great! Thanks a million Rajesh
it because MM in Symfony and mm in jQuery UI return the same
1

Just to make it clear.

in jQuery UI:

mm = "01"
MM = "January"

in Symfony:

mm // is not valid format
MM == "01"

Symfony MM is same as jQuery UI mm

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.