ValidatorFX icon indicating copy to clipboard operation
ValidatorFX copied to clipboard

Add Color Changeable Graphic To Denote a required field

Open colindj1120 opened this issue 2 years ago • 5 comments

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

colindj1120 avatar Sep 10 '23 04:09 colindj1120

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).

effad avatar Sep 11 '23 06:09 effad

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.

colindj1120 avatar Sep 12 '23 17:09 colindj1120

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

reardenSteel1964 avatar Dec 28 '23 19:12 reardenSteel1964

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 avatar May 06 '24 11:05 effad

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

effad avatar May 06 '24 11:05 effad