Skip to content
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

FormElement: Add RadioElement #68

Merged
merged 1 commit into from Dec 14, 2022
Merged

FormElement: Add RadioElement #68

merged 1 commit into from Dec 14, 2022

Conversation

sukhwinder33445
Copy link
Contributor

@sukhwinder33445 sukhwinder33445 commented Aug 15, 2022

@cla-bot cla-bot bot added the cla/signed label Aug 15, 2022
@sukhwinder33445 sukhwinder33445 changed the title Add RadioElement FormElement: Add RadioElement Aug 15, 2022
@sukhwinder33445 sukhwinder33445 self-assigned this Aug 22, 2022
@sukhwinder33445 sukhwinder33445 force-pushed the add-radiobutton-element branch 8 times, most recently from ea466be to e08c13e Compare September 30, 2022 15:23
Copy link
Member

@lippserd lippserd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to the requested changes please

  • use heredoc for the expected HTML and
  • replace validation with something like an InArray validator provided in addDefaultValidators().

src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
@sukhwinder33445
Copy link
Contributor Author

  • replace validation with something like an InArray validator provided in addDefaultValidators().

This will not help much, since we also need to check for the disabled attribute. And all this should be done before parent::validate() is called. 🤔

@lippserd
Copy link
Member

  • replace validation with something like an InArray validator provided in addDefaultValidators().

This will not help much, since we also need to check for the disabled attribute. And all this should be done before parent::validate() is called. 🤔

The value should be validated against a list of possible values. Possible values are all options that are not disabled.

@lippserd
Copy link
Member

Please don't resolve conversations just for fun. I don't see anything resolved in the code.

@sukhwinder33445 sukhwinder33445 force-pushed the add-radiobutton-element branch 7 times, most recently from 96be016 to 6376262 Compare October 26, 2022 09:44
@sukhwinder33445 sukhwinder33445 force-pushed the add-radiobutton-element branch 3 times, most recently from 307eaa9 to 7fa1a50 Compare October 27, 2022 14:08
Copy link
Member

@lippserd lippserd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be InArrayValidator and not InArray, right?

I think it is best to have an option to defer which values to validate against in the InArrayValidator, by passing a callback to retrieve the possible values.

@lippserd
Copy link
Member

It should be InArrayValidator and not InArray, right?

I think it is best to have an option to defer which values to validate against in the InArrayValidator, by passing a callback to retrieve the possible values.

Maybe DeferredInArrayValidator.

src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioOption.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
Copy link
Member

@nilmerg nilmerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing tests:

  • testSetOptionsResetsOptions()
  • testOrderOfOptionsAndDisabledOptionsDoesNotMatter()
  • testGetOptionReturnsPreviouslySetOption()
  •   public function testNullAndTheEmptyStringAreAlsoEquallyHandledWhileDisablingOptions()
      {
          $radio = new RadioElement('radio');
          $radio->setOptions([null => 'Foo', 'bar' => 'Bar']);
          $radio->setDisabledOptions([null]);
    
          $this->assertTrue($radio->getOption(null)->isDisabled());
    
          $radio = new RadioElement('radio');
          $radio->setOptions(['' => 'Foo', 'bar' => 'Bar']);
          $radio->setDisabledOptions(['']);
    
          $this->assertTrue($radio->getOption('')->isDisabled());
    
          $radio = new RadioElement('radio');
          $radio->setOptions([null => 'Foo', 'bar' => 'Bar']);
          $radio->setDisabledOptions(['']);
    
          $this->assertTrue($radio->getOption(null)->isDisabled());
          $radio = new RadioElement('radio');
          $radio->setOptions(['' => 'Foo', 'bar' => 'Bar']);
          $radio->setDisabledOptions([null]);
    
          $this->assertTrue($radio->getOption('')->isDisabled());
      }
  •   public function testGetOptionGetValueAndElementGetValueHandleNullAndTheEmptyStringEqually()
      {
          $radio = new RadioElement('radio');
          $radio->setOptions(['' => 'Foo']);
          $radio->setValue('');
    
          $this->assertNull($radio->getValue());
          $this->assertNull($radio->getOption('')->getValue());
    
          $radio = new RadioElement('radio');
          $radio->setOptions([null => 'Foo']);
    
          $this->assertNull($radio->getValue());
          $this->assertNull($radio->getOption(null)->getValue());
      }

src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioElement.php Outdated Show resolved Hide resolved
src/FormElement/RadioOption.php Outdated Show resolved Hide resolved
tests/FormElement/RadioElementTest.php Outdated Show resolved Hide resolved
@sukhwinder33445 sukhwinder33445 force-pushed the add-radiobutton-element branch 2 times, most recently from 410151f to b37b91d Compare November 29, 2022 13:37
src/FormElement/RadioOption.php Outdated Show resolved Hide resolved
src/FormElement/RadioOption.php Outdated Show resolved Hide resolved
@yhabteab
Copy link
Member

yhabteab commented Dec 6, 2022

Please add an option to render the input fields without wrapping them into the radio-label.

@sukhwinder33445
Copy link
Contributor Author

Please add an option to render the input fields without wrapping them into the radio-label.

Can you explain the use case please?

@yhabteab
Copy link
Member

yhabteab commented Dec 6, 2022

I have a very special use case though that would stretch the scope to explain here but in short, I don't want the inputs to be wrapped in a label that I can neither access it with getWrapper() nor override it.

@nilmerg nilmerg removed the request for review from lippserd December 14, 2022 09:16
@nilmerg nilmerg merged commit 638acb7 into master Dec 14, 2022
@nilmerg nilmerg deleted the add-radiobutton-element branch December 14, 2022 09:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla/signed enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants