Open WinterSilence opened 2 years ago
Framework works exactly as documentation says and it allows developer to override default behavior if needed in cases like this.
Documentation for BaseHtml::activeCheckboxList()
and BaseHtml::activeRadioList()
clearly says:
@param array $options options (name => config) for the checkbox list / radio button container tag. The following options are specially handled: ...
- unselect: string, the value that should be submitted when none of the checkboxes / radio buttons is selected. You may set this option to be null to prevent default value submission. If this option is not set, an empty string will be submitted.
Per documentation:
If Form::$values
isn't intended to allow unselect, 'unselect'
should be set to null
and that works without issue as designed:
echo $form->field($model, 'values[]')->checkboxList([1 => 'foo', 2 => 'bar'], ['unselect' => null]);
Also, if Form::$values
expect any other value for unselect, custom value can be set and that works without issue as designed:
echo $form->field($model, 'values[]')->checkboxList([1 => 'foo', 2 => 'bar'], ['unselect' => 0]);
IMHO, this isn't bug and should be closed.
Also, as both @rob006 and I stated in PR #19447 discussion, if Model::load()
throws exception, issue is in concrete Model
implementation, not in helper for printing forms. If invalid data is submitted (which doesn't need to be submitted exclusively via form printed using this helper), that should trigger validation error, not exception.
What steps will reproduce the problem?
Model:
View:
Controller:
What is the expected result?
No errors on load form data into model when i don't check values
What do you get instead?
Error: can't set string to array property
$values
because https://github.com/yiisoft/yii2/blob/f72310c398759841a0f8b52e1aba7990086c0d9c/framework/helpers/BaseHtml.php#L1845Additional info