Skip to content

feat: integrate client-side validation into ComboBox - #4323

Merged
sissbruecker merged 8 commits into
masterfrom
feat/combobox_chained_validation
Dec 9, 2022
Merged

sissbruecker merged 8 commits into
masterfrom
feat/combobox_chained_validation

Conversation

@sissbruecker

Copy link
Copy Markdown
Member

Description

Makes ComboBox and MultiSelectComboBox validate on the server-side when the client attempts to validate, which means that server-side validation is now also triggered on blur. Also integrates with Binder, so that Binder validation is now also triggered when the component attempts to validate.

Closes #4237
Closes #4238

Type of change

  • Feature

addCard("Helper text and helper component", div);
}

private void configurationForRequired() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Seemingly unused test setup.

import com.vaadin.flow.router.Route;

@Route("vaadin-combo-box/required-combobox")
public class RequiredComboboxPage extends Div {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Seemed to cover required and custom validation with Binder.

import com.vaadin.flow.router.Route;

@Route("vaadin-combo-box/required-combobox-startup")
public class RequiredComboboxStartupPage extends Div {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Seemed to cover attaching initially invalid field.

@Tag("validation-connector")
@JsModule("./src/validation-connector.js")
@Route("vaadin-combo-box/validation-connector")
public class ValidationConnectorErrorPage extends PolymerTemplate<TemplateModel>

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This was a regression test for a client-side script error that occured when enabling required validation through the connector. Obsolete as the connector calls have been removed.

}

@Test
public void required_customValuesAllowed_assertValidity() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added additional test where custom values are allowed. Probably doesn't make a difference to selecting a predefined value, as the test setup handling custom values is also just changing the component's value. Still can't hurt I guess?


@Test
public void required_changeValue_assertValidity() {
$("input").id(EXPECTED_VALUE_INPUT).sendKeys("foo", Keys.ENTER);

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I added custom validation to the Binder tests, as when allowing custom values, the user is mostly free to enter anything. This test does not allow custom values, just testing it here as well for completeness sake.

Also the test process differs a bit from the input field ones: For the input fields, custom validation was tested as part of the constraint tests. Combo box does not have any constraints, so I attempted to add this to the required tests.

}

@Test
public void required_customValuesAllowed_changeValue_assertValidity() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Additional test for required validation when allowing custom values.

assertErrorMessage(UNEXPECTED_VALUE_ERROR_MESSAGE);

// Binder validation passes
testField.deselectAll();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Multi-select combo box needs to be cleared after each step, otherwise it would just select additional values.

}

@Override
public void setRequiredIndicatorVisible(boolean requiredIndicatorVisible) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Removing this breaks binary compatibility (super method is in an interface instead of class). Should not be back-ported as is.

/**
* Deselects all items, effectively clearing the value.
*/
public void deselectAll() {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Added convenience method for deselecting all values.

Another option would have been to override clear, however it didn't seem appropriate for clearing the selection, as the JavaDoc mentions that it's supposed to clear input elements specifically.

@sissbruecker
sissbruecker marked this pull request as ready for review December 9, 2022 07:15
@sissbruecker
sissbruecker requested a review from vursen December 9, 2022 07:15
@sonarqubecloud

sonarqubecloud Bot commented Dec 9, 2022

Copy link
Copy Markdown

SonarCloud Quality Gate failed.    Quality Gate failed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell D 91 Code Smells

No Coverage information No Coverage information
3.1% 3.1% Duplication

@vaadin-bot

Copy link
Copy Markdown
Collaborator

This ticket/PR has been released with Vaadin 24.0.0.alpha6 and is also targeting the upcoming stable 24.0.0 version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[MultiSelectComboBox] Implement the new validation behavior [ComboBox] Implement the new validation behavior

3 participants