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

Add Color Changeable Graphic To Denote a required field #35

Open
colindj1120 opened this issue Sep 10, 2023 · 5 comments
Open

Add Color Changeable Graphic To Denote a required field #35

colindj1120 opened this issue Sep 10, 2023 · 5 comments

Comments

@colindj1120
Copy link

Allow someone to set a field as required which shows some icon graphic that they can change the color of.

@effad
Copy link
Owner

effad commented Sep 11, 2023

I am not sure I understand your requirement correctly. This can easily be done, like this:

...
		TextField userTextField = new TextField();
		validator.createCheck()
			.withMethod(this::required)
			.dependsOn("text", userTextField.textProperty())
			.decorates(userTextField)
			.immediate()
...
	private void required(Context context) {
		String text = context.get("text");
		if (text == null || text.isEmpty()) {
			context.error("This field is required.");
		}
	}

Note that required may use text.isBlank() instead of isEmpty if you want to disallow all-whitespace input. And depending on your type of Control you may need to implement things differently (e.g. a ComboBox has a valueProperty, not a textProperty).

@colindj1120
Copy link
Author

I was thinking in the terms of Controls FX where if you set the required flag to true there is a little red caret in the top right corner of the text box. I hadn't found a way to change the caret color or caret icon type. This caret stays there indefinitely and then the little circle red x icon is displayed in the bottom right corner when the validation fails. I was wondering if ValidatorFX allowed the same and also allowed for changing of the icon/color.

@reardenSteel1964
Copy link

A required field indicator like this would be nice addition. +1.

@effad
Copy link
Owner

effad commented May 6, 2024

This can already be done by providing your own default decoration factory:
Call (net.synedra.validatorfx.DefaultDecoration.setFactory(Function<ValidationMessage, Decoration>) and pass it a factory that will create its own GraphicDecoration (using whatever icon you have / want).

@effad
Copy link
Owner

effad commented May 6, 2024

TODO: I should write about the DefaultDecoration in the README.md ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants