Skip to content

Commit

Permalink
fix radio typecast
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Feb 16, 2024
1 parent c52f0c9 commit df68238
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 9 deletions.
10 changes: 5 additions & 5 deletions demos/form-control/form6.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@
$form->addControl('enum_d', [], ['enum' => ['female', 'male']])->set('male');
$form->addControl('enum_r', [Form\Control\Radio::class], ['enum' => ['female', 'male']])->set('male');

$form->addControl('list_d', [], ['values' => ['female', 'male']])->set(1);
$form->addControl('list_r', [Form\Control\Radio::class], ['values' => ['female', 'male']])->set(1);
$form->addControl('list_d', [], ['type' => 'integer', 'values' => ['female', 'male']])->set(1);
$form->addControl('list_r', [Form\Control\Radio::class], ['type' => 'integer', 'values' => ['female', 'male']])->set(1);

$form->addControl('int_d', [], ['values' => [5 => 'female', 7 => 'male']])->set(7);
$form->addControl('int_r', [Form\Control\Radio::class], ['values' => [5 => 'female', 7 => 'male']])->set(7);
$form->addControl('int_d', [], ['type' => 'integer', 'values' => [5 => 'female', 7000 => 'male']])->set(7000);
$form->addControl('int_r', [Form\Control\Radio::class], ['type' => 'integer', 'values' => [5 => 'female', 7000 => 'male']])->set(7000);

$form->addControl('string_d', [], ['values' => ['F' => 'female', 'M' => 'male']])->set('M');
$form->addControl('string_r', [Form\Control\Radio::class], ['values' => ['F' => 'female', 'M' => 'male']])->set('M');

$form->onSubmit(static function (Form $form) use ($app) {
return new JsToast($app->encodeJson($form->model->get()));
return new JsToast($app->encodeJson($form->getApp()->uiPersistence->typecastSaveRow($form->model, $form->model->get())));
});
2 changes: 1 addition & 1 deletion src/Form.php
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ protected function loadPost(): void
}

try {
if ($control instanceof Control\Dropdown || $control instanceof Control\Lookup) { // this condition is definitely unacceptable, also should Control::set() be in the catch?
if ($control instanceof Control\Dropdown || $control instanceof Control\Lookup || $control instanceof Control\Radio) { // this condition is definitely unacceptable, also should Control::set() be in the catch?
$control->set($this->getApp()->uiPersistence->typecastAttributeLoadField($control->entityField->getField(), $postRawValue));
} else {
$control->set($this->getApp()->uiPersistence->typecastLoadField($control->entityField->getField(), $postRawValue));
Expand Down
2 changes: 1 addition & 1 deletion src/Form/Control/Radio.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function renderView(): void
$lister->tRow->dangerouslySetHtml('disabled', 'readonly="readonly"');
}

$lister->tRow->set('value', $this->getApp()->uiPersistence->typecastSaveField($this->entityField->getField(), $lister->currentRow->getId()));
$lister->tRow->set('value', $this->getApp()->uiPersistence->typecastAttributeSaveField($this->entityField->getField(), $lister->currentRow->getId()));

$lister->tRow->dangerouslySetHtml('checked', $lister->currentRow->compare($lister->model->idField, $value) ? 'checked="checked"' : '');
});
Expand Down
4 changes: 2 additions & 2 deletions tests-behat/radio.feature
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Feature: Radio
When I press button "Save"
Then Toast display should contain text '"enum_d": "male", "enum_r": "male"'
Then Toast display should contain text '"list_d": "1", "list_r": "1"'
Then Toast display should contain text '"int_d": "7", "int_r": "7"'
Then Toast display should contain text '"int_d": "7 000", "int_r": "7 000"'
Then Toast display should contain text '"string_d": "M", "string_r": "M"'

Then I select value "female" in lookup "enum_d"
Expand All @@ -15,7 +15,7 @@ Feature: Radio
When I press button "Save"
Then Toast display should contain text '"enum_d": "female", "enum_r": "female"'
Then Toast display should contain text '"list_d": "0", "list_r": "0"'
Then Toast display should contain text '"int_d": "7", "int_r": "7"'
Then Toast display should contain text '"int_d": "7 000", "int_r": "7 000"'
Then Toast display should contain text '"string_d": "M", "string_r": "M"'
Then I select value "female" in lookup "int_d"
When I click using selector "//div.ui.radio[not(self::*.checked)][input[@name='int_r'] and label[text()='female']]"
Expand Down

0 comments on commit df68238

Please sign in to comment.