Answer the question
In order to leave comments, you need to log in
How to set the desired data format in symphony2 before validation?
I have a form where there are fields with a checkbox and a datetime field on which the datepicker hangs.
1) I removed the checkbox validation. In Entity, this field has a boolean value. If the checkbox is checked, then 1, but if not, then an empty value, a should be 0.
2) How to convert the datetimepicker value Y/m/d h:i
to Y-m-d H:i:0
.
Tried for checbox via transformer data, but didn't work. And it seems to me that this is not quite the right way.
Answer the question
In order to leave comments, you need to log in
It's probably better to configure the datetimepicker in js to the format used in the form. Or vice versa, configure the form to the datetimepicker format. Why bother with crutches?
For a form it's like this:
$builder->add('date', DateType::class, array(
'widget' => 'single_text',
// this is actually the default format for single_text
'format' => 'yyyy-MM-dd',
));
I will answer the first part of the question.
There was a discussion on github regarding checkboxes. I can't find it now.
In general, you will not get the coveted zero, since the checkbox was implied as a boolean mandatory value.
Use ChoiceType and be happy.
The second one has already been answered.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question