-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[BUG]: Attribute 'checked' in Check element #15959
Comments
Can you try setting the $checkField = new \Phalcon\Forms\Element\Check('checkField');
$checkField
->setAttribute('value', 'one-two-three')
->setAttribute('checked', 'one-two-three')
;
echo $checkField; |
It works in that configuration |
I am closing this but will tag it as documentation so as to update the documents accordingly |
@niden this solution seems to be workaround and not real solution. There can be checkboxes without value created just to represent actual state. |
Can you give me an example please? |
@niden I have a big project with many forms where i have checkboxes. Now in every checkbox that is only used for preview and that worked on v2, v3 and v4 (yes its old project mvp was building on v1) i have to modify code like this:
into this:
because this value has no other meaning than to make "checked" worked. I thought maybe this could work:
but it is not. I have to add value to checkboxes just to make it work. I can and probably do that but it`s workaround not a solution and potencialy a source of problems couse its easy to forget that $checkField->setAttribute('xyz', 'xyz'); will work and set attribute on field, but $checkField->setAttribute('checked', 'checked') will not work and will not set attribute on the field becouse in 'checked' you have to add value before and set this value to checked. Sounds like a bug. |
Yes, setAttribute() is definately not the solution. In Phalcon 3/4 the checked attribute was true of false when the Entities property value was the same as the default value attribute. For example: $status = new Check('status ', [
'value' => '1',
]);
$status ->setLabel('Status');
$this->add($status ); Worked out of the box when $form->render('status'); <input type="checkbox" id="status" name="status" value="1" checked="checked"> In Phalcon 5 the checked attribute is not automatically set anymore. <input type="checkbox" id="status" name="status" value="1"> This is my current workaround: $status = new Check('status', [
'value' => 1,
]);
if (!is_null($entity)) {
$status->setAttribute('checked', $entity->status);
}
$status->setLabel('Status');
$this->add($status); |
@niden I was looking further into the issue. I think the issue lies in the fact that the value in $entity->active is 1 as an integer and not '1' a string. So the check on line 127 in https://github.com/phalcon/cphalcon/blob/master/phalcon/Html/Helper/Input/Checkbox.zep#L127 fails because is strict with ===. |
I also have a similar problem, because of which I can not upgrade to version 5 |
Temporary solution sitchi@00e0015 |
I found another bug related to checkbox when using '0' as unchecked value.
Expected Result Actual Result |
I got another vector for this issue. For now I use this temporary fix: $this->tag->set('inputCheckbox', CheckboxRendererFix::class); class CheckboxRendererFix extends \Phalcon\Html\Helper\Input\Checkbox
{
private function processChecked(): void
{
$attributes = $this->attributes;
if (empty($attributes['checked'])) {
if (!empty($attributes['value'])) {
$attributes['checked'] = 'checked';
}
}
$this->attributes = $attributes;
}
} |
The main issue here is the test of
As @amujib stated, testing So instead of Can you fix this? Or should I open another bug report @niden? |
@niden something like:
|
If you don't mind please add an issue and reference this discussion/tag me. Sorry guys, too busy at work to remember all these discussions :/ |
@bakos regarding your initial report: checkboxes always have a value. If you POST a checkbox, you'll see that PHP considers its value to be Radio fields are different as it should be considered as a @niden there's another issue with this, as |
What! Is selected if the value property value and the checked property value are the same. `
` I did it as follows and it worked.
I think the team was a little confused while writing |
Describe the bug
In Phalcon 5.0.x Check field clears 'checked' attribute on render.
To Reproduce
Expected behavior
It should render html with attribute 'checked'. It works in phalcon 4.x, 3.x
Screenshots
Phalcon 4
Phalcon 5
Details
Additional context
I tried this on attribute 'disabled' and it was working, so the bug is not about setting any attribute
The text was updated successfully, but these errors were encountered: