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

Provide default checks #4

Open
effad opened this issue Dec 12, 2019 · 4 comments
Open

Provide default checks #4

effad opened this issue Dec 12, 2019 · 4 comments
Labels
enhancement New feature or request

Comments

@effad
Copy link
Owner

effad commented Dec 12, 2019

Some checks (field required, max input length, etc.) are so common we should provide convenience ways of adding them

@effad effad added the enhancement New feature or request label Jan 30, 2020
@georgemoralis
Copy link

yes that might be extremely helpful for not duplicate code all over

@effad
Copy link
Owner Author

effad commented Mar 17, 2021

Since warning/error-messages must be translatable (i18n), these messages must always be provided by the client of ValidatorFX.

Here are things that I would consider common checks:

  • Field is required (i.e. it must not be empty)
  • Field must have a minimum length
  • Field must not exceed a maximum length
  • Field must be a number (separate checks for int/long/double, etc.)
    • With min/max value range
  • Field must match a regular expression

Most of these checks may only be applied to TextInputControls (i.e. TextField/TextArea), since its textProperty() will be checked.

The required-check should be applicable to all kinds of Controls but will require separate convenience-methods for different kinds of controls (TextInputControls must be checked against textProperty().isBlank(); ComboBox must be checked against valueProperty() != null, etc.)

@georgemoralis If you have more suggestions as to what you would expect as convenience methods, please tell me.

@georgemoralis
Copy link

i have done some validators using controlsfx validator you can check here

https://github.com/codebbgr/protoERP/blob/main/src/main/java/gr/codebb/protoerp/util/validation/Validators.java

probably something similar can be done here :D

@effad
Copy link
Owner Author

effad commented Jul 12, 2022

Considering the following piece of code:

		validator.createCheck()
			.dependsOn("usePatientId", usePatientId.selectedProperty())
			.dependsOn("useName", useName.selectedProperty())
			.dependsOn("exactBirthDate", exactBirthDate.selectedProperty())
			.dependsOn("theFirst", theFirst.selectedProperty())
			.withMethod(c -> {
				if (!(boolean) c.get("usePatientId") && !(boolean)  c.get("useName") && !(boolean)  c.get("exactBirthDate")  && !(boolean)  c.get("theFirst")) {
					c.error(LC.MustSelectAtLeastOneCriterion());
				}
			})
			.immediate()
		;

it would be nice to:

  • be able to iterate over all the values of a Check.Context (not only .get them).
  • have a default-function to check that one of the boolean properties we depend on must be true.

This would allow :

		validator.createCheck()
			.dependsOn("usePatientId", usePatientId.selectedProperty())
			.dependsOn("useName", useName.selectedProperty())
			.dependsOn("exactBirthDate", exactBirthDate.selectedProperty())
			.dependsOn("theFirst", theFirst.selectedProperty())
			.withMethod(c -> atLeastOneMustBeTrue(c))
			.immediate()
		;

Shahondin1624 added a commit to Shahondin1624/ValidatorFX that referenced this issue May 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants