0

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!

4
  • 1
    Why do you have the string 'empty_value' for '--- Choose ---' it should be just '' if you want it to constrain against notblank Commented Aug 9, 2012 at 11:20
  • Thank you very much! :) I saw an example where it was 'empty_value' and I thought that it be this way. ;d Commented Aug 9, 2012 at 11:24
  • 1
    how do you display the date item? Commented Aug 9, 2012 at 11:26
  • This way <td>{{ var.someDate|date('Y-m-d')}}</td> Commented Aug 9, 2012 at 11:28

2 Answers 2

2

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") }}
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you for helping me so much and answering on almost every question of mine! I appreciate it very much!
0

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.

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.