0
votes

I have some questions all conected, so I will ask all of them here:

  1. [Solved] I have date fields which can be nullable and when I don't fill them they are displayed as 2012-08-09 - today's date, although when I check in the database they are NULL. I have @ORM\Column(type="date", nullable=true) and @Assert\Date above both of them.

  2. I have form validation @Assert\Date and @Assert\NotBlank() but I violate this constrains nothing happens although I have {{ form_errors(form) }}. How to show what exactly is wrong with the form?

  3. [Solved] The last one is that I have NotBlank() constrain above a field called $currency. This is how I add it:

    $builder->add('currency', 'choice', array(
        'choices' => array(
            'empty_value' => '--- Choose ---', 'USD' => 'USD', 'HKD' => 'HKD')));
    

    but if I don't set anything (it stays --- Choose ---- ) it accepts it, although it's empty. I want the default choice to be --- Choose ---, but it musn't be allowed to leave it this way and the form to be valid in the same time.

I would appreciate your help!

2
Why do you have the string 'empty_value' for '--- Choose ---' it should be just '' if you want it to constrain against notblankgunnx
Thank you very much! :) I saw an example where it was 'empty_value' and I thought that it be this way. ;dFaery
how do you display the date item?Carlos Granados
This way <td>{{ var.someDate|date('Y-m-d')}}</td>Faery

2 Answers

2
votes

For the first question, taken from the twig documentation:

If the value passed to the date filter is null, it will return the current date by default. If an empty string is desired instead of the current date, use a ternary operator:

{{ post.published_at is empty ? "" : post.published_at|date("m/d/Y") }}
0
votes

For the second question there is information here Symfony2 : How to get form validation errors after binding the request to the form Sorry for not finding it earlier and questioning something that have been already questioned.