A
A
Arx7772016-02-11 15:33:04
symfony
Arx777, 2016-02-11 15:33:04

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:ito 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

3 answer(s)
E
Evgeny Svirsky, 2016-02-11
@e_svirsky

hmm, a bit of code...

J
jaxel, 2016-02-11
@jaxel

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',
));

D
Denis, 2016-02-16
@prototype_denis

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 question

Ask a Question

731 491 924 answers to any question