-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
[Form] Couldn't set invalid_message for DateType #5880
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
btw, by default, If I select (nothing)-(1)-(1) at following form,I will get "This value is not valid." twice $form = $this->createFormBuilder()
->add('birthdate','birthday',array(
'empty_value'=>array(
'year'=>'year',
'month'=>'month',
'day'=>'day'
),
'widget'=>'choice'
))->getForm(); |
or we can disable the error_bubbling and assume they are a whole? |
I'd like to edit the So, this does not work: /**
* @Assert\Valid(message="Custom invalid message")
*/ And this does not work either: $formBuilder->add('editor', 'entity', array(
'required' => true,
'constraints' => new Valid(array('message' => 'Custom invalid message')),
'invalid_message' => 'Custom invalid message',
)); |
What about this bug? Because it's 2017 and I'm facing now this issue :) Solution provided by @scourgen looks ok. If you don't want to add separated messages for year, month, day then add just $yearOptions['invalid_message'] = $options['invalid_message'];
$monthOptions['invalid_message'] = $options['invalid_message'];
$dayOptions['invalid_message'] = $options['invalid_message']; because now when error occurs in one of the sub types (year|month|day) then message is always "This value is not valid." and we cannot change it. |
@awudarowicz Do you want to provide a fix ? |
…abbuh) This PR was merged into the 2.8 branch. Discussion ---------- [Form] forward the invalid_message option in date types | Q | A | ------------- | --- | Branch? | 2.8 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | Fixed tickets | #5880 | License | MIT | Doc PR | Commits ------- 5318e2e forward the invalid_message option in date types
in my case, I have a form,that has a date column,and I want validate this date column like this: If user did something wrong,I would like to tell them what happen(forgot or typed/select the wrong date)
I assume what could happen is like:
But I found out that I could't set the invalid_message for each input(year/month/day)
the truth is I can't define the invalid_message separately. When I typed wrong, I always get the error "This value is not valid."
so I spent some time on the code, finally I got this:
Symfony/Component/Form/Extension/Core/Type/DateType.php
looks like It doesn't pass the invalid_message to field year/month/day . so when the field gets wrong,It will always shows the default message . I can't even change it !
I made a simple fix like following code:
so I can define them separately like following:
The text was updated successfully, but these errors were encountered: