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 internal state validators for HasValue #9532

Merged
merged 5 commits into from Jul 3, 2017

Conversation

tsuoanttila
Copy link
Contributor

@tsuoanttila tsuoanttila commented Jun 14, 2017

This change is Reviewable

@elmot
Copy link
Contributor

elmot commented Jun 19, 2017

Reviewed 4 of 5 files at r1.
Review status: 4 of 5 files reviewed at latest revision, 2 unresolved discussions.


server/src/main/java/com/vaadin/data/HasValue.java, line 301 at r1 (raw file):

    /**
     * Returns a validator that checks the internal state of the HasValue. This

Is the javadoc really clear for an app developer?
What about text like "This method should be overwritten for components with internal value validation like text input for dates. If user text is unparseableas a date, then that should be exposed to Binder by using default component validator".


server/src/main/java/com/vaadin/data/HasValue.java, line 305 at r1 (raw file):

     * date. A faulty input from user can be seen as a validation failure.
     * 
     * @return internal state validator

@since


Comments from Reviewable

@elmot elmot requested a review from hesara June 29, 2017 07:56
@elmot
Copy link
Contributor

elmot commented Jul 3, 2017

Reviewed 1 of 1 files at r2.
Review status: all files reviewed at latest revision, all discussions resolved.


Comments from Reviewable

@hesara hesara merged commit dde0f91 into master Jul 3, 2017
@hesara hesara deleted the datefield_default_validator branch July 3, 2017 07:51
@hesara hesara added this to the 8.1.0.rc1 milestone Jul 3, 2017
@anasmi
Copy link
Contributor

anasmi commented Jul 10, 2017

Still some problem exists with validation

  • Set malformed date --> call a binder validation --> remove date field content-->call a binder validation another time => the validation failed. (Field is set to be in non-required mode)
    -Also setting malformed input (abc, for example) --> validating returns error, but no visual representation then setting the right value makes textfield red
    visualvalidation

Code to reproduce:
`

         final VerticalLayout layout = new VerticalLayout();

	DateField dateField = new DateField("Date");
	dateField.setParseErrorMessage("Parse error");
	dateField.setDateOutOfRangeMessage("Out of range");
	layout.addComponent(dateField);
	dateField.addValueChangeListener(event -> {
		System.out.println(dateField.getValue());
	});
	Label errorLabel = new Label();
	layout.addComponent(errorLabel);

	Binder<Void> binder = new Binder<>();
	binder.forField(dateField).withStatusLabel(errorLabel).bind(o -> dateField.getEmptyValue(), null);

	Button button = new Button("Validate!");
	button.addClickListener(event1 -> {
		if (binder.validate().isOk()) {
			System.out.println("Correct");
		} else {
			System.out.println(dateField.isEmpty() + "Error!");
		}
	});
	layout.addComponent(button);

	setContent(layout);`

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

Successfully merging this pull request may close these issues.

None yet

4 participants