Skip to content

Commit

Permalink
refactor: remove setRequired and isRequired as unnecessary
Browse files Browse the repository at this point in the history
  • Loading branch information
web-padawan committed Apr 16, 2024
1 parent a111640 commit f12b455
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 44 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ public class Checkbox extends AbstractSinglePropertyField<Checkbox, Boolean>
private String ariaLabel;
private String ariaLabelledBy;

private boolean required;
private boolean manualValidationEnabled = false;

/**
Expand Down Expand Up @@ -323,34 +322,6 @@ public boolean isIndeterminate() {
return getElement().getProperty("indeterminate", false);
}

/**
* Sets whether the checkbox is marked as input required.
*
* @since 24.5
* @param required
* the boolean value to set
*/
public void setRequired(boolean required) {
getElement().setProperty("required", required);
this.required = required;
}

/**
* Determines whether the checkbox is marked as input required.
*
* @since 24.5
* @return {@code true} if the input is required, {@code false} otherwise
*/
public boolean isRequired() {
return getElement().getProperty("required", false);
}

@Override
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible) {
super.setRequiredIndicatorVisible(requiredIndicatorVisible);
this.required = requiredIndicatorVisible;
}

@Override
public void setManualValidation(boolean enabled) {
this.manualValidationEnabled = enabled;
Expand All @@ -373,8 +344,9 @@ protected void validate() {
* constraints using browser development tools.
*/
private boolean isInvalid(Boolean value) {
boolean isRequired = isRequiredIndicatorVisible();
ValidationResult requiredValidation = ValidationUtil
.checkRequired(required, value, getEmptyValue());
.checkRequired(isRequired, value, getEmptyValue());

return requiredValidation.isError();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,20 +150,6 @@ public void setAriaLabelledBy() {
Assert.assertTrue(checkbox.getAriaLabelledBy().isEmpty());
}

@Test
public void setRequired_isRequired() {
Checkbox checkbox = new Checkbox();

Assert.assertFalse(checkbox.isRequired());
Assert.assertFalse(
checkbox.getElement().getProperty("required", false));

checkbox.setRequired(true);

Assert.assertTrue(checkbox.isRequired());
Assert.assertTrue(checkbox.getElement().getProperty("required", false));
}

@Test
public void implementsInputField() {
Checkbox field = new Checkbox();
Expand Down

0 comments on commit f12b455

Please sign in to comment.