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

returnBlankAsNull for AbstractValueWidget #753

Closed
jzaruba opened this issue Dec 16, 2017 · 9 comments
Closed

returnBlankAsNull for AbstractValueWidget #753

jzaruba opened this issue Dec 16, 2017 · 9 comments
Assignees
Milestone

Comments

@jzaruba
Copy link
Contributor

jzaruba commented Dec 16, 2017

Hello

I need MaterialTextBox to return null instead of blank value. So I extended it like this:

public class MaterialTextBox extends gwt.material.design.client.ui.MaterialTextBox {
        /**
         * If true #getValue will return null when the value is blank
         */
	private boolean returnBlankAsNull = false;

	public boolean isReturnBlankAsNull() {
		return this.returnBlankAsNull;
	}

	public void setReturnBlankAsNull(boolean returnBlankAsNull) {
		this.returnBlankAsNull = returnBlankAsNull;
	}

	@Override
	public String getValue() {
		if(isReturnBlankAsNull() && isBlank()) {
			return null;
		}
		return super.getValue();
	}

	protected boolean isBlank() {
		return !createBlankValidator().isValid(super.getValue());
	}
}

I have added the new attribute to MaterialTextBox but I believe it should eventually go to gwt.material.design.client.base.AbstractValueWidget.

Would you consider accepting this modification i.e. a pull request?

@jzaruba
Copy link
Contributor Author

jzaruba commented Dec 16, 2017

Typical use-case would be non-mandatory inputs/fields with @Pattern constraint, like e-mail or phone number. In such cases the POJO you get from the editor will have "" in its String fields, and validation will test @Pattern.regexp against "", which usually fails.
While there are other solutions to the situation (a pipe in your regexp, preprocessing your POJO, ...), personally I like the null-approach the best.

@BenDol
Copy link
Collaborator

BenDol commented Dec 16, 2017

This would be acceptable, however note that there are edge cases in classes like MaterialValueBox where the getValue is accessing its value from the valueBoxBase. So you will have to perform the check there also (at least until that class is rewritten).

@BenDol
Copy link
Collaborator

BenDol commented Dec 16, 2017

In fact you will have to make sure all the classes extending MaterialValueBox call super.getValue() before accessing the value for real and handle it appropriately. I would be okay reviewing a PR if you want to submit one. Thanks!

@jzaruba
Copy link
Contributor Author

jzaruba commented Dec 17, 2017

Which branch should the changes go to please?

@BenDol
Copy link
Collaborator

BenDol commented Dec 18, 2017

release_2.1

jzaruba pushed a commit to jzaruba/gwt-material that referenced this issue Dec 23, 2017
…ed `#returnBlankAsNull`, with this attribute set to `true` calling `#getvalue()` returns `null` when the (already implemented) blank-validator recognizes the value blank
@jzaruba
Copy link
Contributor Author

jzaruba commented Dec 23, 2017

In the end it seems MaterialValueBox is actually the best place to implement the change.

kevzlou7979 added a commit that referenced this issue Jan 4, 2018
#753 - MaterialValueBox now has a new attribute called #returnBlankAsNull
@kevzlou7979
Copy link
Contributor

kevzlou7979 commented Jan 4, 2018

Agreed this can be used also not only in MaterialTextBox but also all widget extending ValueBox

@kevzlou7979
Copy link
Contributor

I'm writing now the Documentation on the Latest 2.1 demo snapshot and also A JUnit test for this.

@kevzlou7979
Copy link
Contributor

kevzlou7979 commented Jan 4, 2018

Demo Added
test1

JUnit Added
3a938d1

@kevzlou7979 kevzlou7979 added this to the 2.1 milestone Jan 4, 2018
kevzlou7979 added a commit that referenced this issue Jan 17, 2018
- Added getEmptyPlaceHolder() and added validation checks on removeEmptyPlaceHolder().
-  Added testEmptyPlaceHolder test cases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants