Hi,
I needed a boolean custom field in an edit form. I added it to the
generator.yml, and I added the checkbox widget in the form configure
method. I also added the getter and setter methods in the model.
The one problem I did have is that changes in the checkbox were being
ignored. I had to log the setter to find out that the value it was
receiving was not a boolean true/false, but a 'on' string. Ok, I could
have thought of that... but I was expecting symfony to handle the
conversion from the html field value to my custom field value, like it
does for the non-custom fields.
Anyway, I temporarily solved it this way:
public function setCustomField($value) {
if ($value === true || $value == 'on')
$this->customField = true;
else
$this->customField = false;
}
I suppose I could refactor it to:
public function setCustomField($value) {
$this->customField = ($value === true || $value == 'on');
}
... but I was actually hoping there was something better. Are there
some primitives or php/symfony functions to handle these type
conversions in a standard way? Any best practice?
TIA and regards,
Marco Rocci
--
If you want to report a vulnerability issue on symfony, please send it to
security at symfony-project.com
You received this message because you are subscribed to the Google
Groups "symfony users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/symfony-users?hl=en