Go Back   SmartClient Forums > Smart GWT Technical Q&A
Wiki Register Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #11  
Old 5th Jun 2012, 09:01
yathish.venkatesh yathish.venkatesh is offline
Registered Developer
 
Join Date: Sep 2011
Posts: 64
Default

So adding "^" at the beginning and "$" at the end would resolve my issue. Let me try and let you know.

Thanks for your help.
Reply With Quote
  #12  
Old 7th Jun 2012, 05:10
yathish.venkatesh yathish.venkatesh is offline
Registered Developer
 
Join Date: Sep 2011
Posts: 64
Default

This worked fine. Thanks.

But i have a another issue. I have a select item and a text item. the default validation works fine but once i change select item required validation wont work.

Here is my code.

Code:
TextItem origin = new TextItem();
origin.setRequired(true);
RegExpValidator validator = new RegExpValidator();
validator.setExpression("^(([A-Z0-9]{3})+)(,([A-Z0-9]{3})+)*(,)*$"); //which validates airports but not the country.
origin.setValidators(validator);

SelectItem selectType = new SelectItem();
selectType .setValueMap("Airport", "Country");
selectType.addChangedHandler(new ChangedHandler() {
            public void onChanged(ChangedEvent changedEvent) {
                 origin.setRequired(true);
                 getField("origin").clearValue();
                 RegExpValidator validator = new RegExpValidator();
                 if((String) changedEvent.getValue().equalsignorecase("Airport)
                    validator.setExpression("^(([A-Z0-9]{3})+)(,([A-Z0-9]{3})+)*(,)*$"); 
                else 
                    validator.setExpression("^(([A-Z0-9]{2})+)(,([A-Z0-9]{2})+)*(,)*$"); 
}
Note that, regardless of the selection of Airport/country, it should validate a textItem for required field. If it is Default(Airport selected) error message displays. But if i change it to Country Required field validation fails.

Please let me know what is the issue/is it a known issue?
Reply With Quote
  #13  
Old 7th Jun 2012, 11:58
Isomorphic Isomorphic is online now
Administrator
 
Join Date: May 2006
Posts: 37,501
Default

This code isn't making much sense - a validator is created on the fly but not attached to anything? And it shows setting a field to required that is already required.

Please examine these problems - if you need more help, please re-explain the issue then show code that we can run to see the problem.
Reply With Quote
  #14  
Old 7th Jun 2012, 21:12
yathish.venkatesh yathish.venkatesh is offline
Registered Developer
 
Join Date: Sep 2011
Posts: 64
Default

I have attached this validator at runtime to the TextItem, which i missed while typing.

But even though, i have set required field, it wont throws error. Here is my final code.

Code:
final TextItem origin = new TextItem();
origin.setRequired(true);
RegExpValidator validator = new RegExpValidator();
validator.setExpression("^(([A-Z0-9]{3})+)(,([A-Z0-9]{3})+)*(,)*$"); //which validates airports but not the country.
origin.setValidators(validator);

final SelectItem selectType = new SelectItem();
selectType .setValueMap("Airport", "Country");
selectType.addChangedHandler(new ChangedHandler() {
	public void onChanged(ChangedEvent changedEvent) {
		getField("origin").clearValue();
		RegExpValidator validator = new RegExpValidator();
		if((String) changedEvent.getValue().equalsignorecase("Airport)
			validator.setExpression("^(([A-Z0-9]{3})+)(,([A-Z0-9]{3})+)*(,)*$"); 
		else 
			validator.setExpression("^(([A-Z0-9]{2})+)(,([A-Z0-9]{2})+)*(,)*$");
		origin.setValidators(validator);
	}
}
Reply With Quote
  #15  
Old 8th Jun 2012, 11:36
Isomorphic Isomorphic is online now
Administrator
 
Join Date: May 2006
Posts: 37,501
Default

We don't recommend changing validators on the fly, it has a lot of ambiguity with respect to what is supposed to happen to existing errors and values that may have just become invalid as of new validators being applied. If your validator is conditional, add it as a custom validator.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to align buttons beneath a dynamic form (populated from datasource) kieser Smart GWT Technical Q&A 8 7th Oct 2012 17:26
Why forms' items dont have name property Ataman997 Smart GWT Technical Q&A 10 4th May 2012 11:23
Tab order with custom form item mgbf Smart GWT Technical Q&A 4 24th Jan 2012 12:55
How to overwrite default fielnd in Calendar's eventEditor Ataman997 Smart GWT Technical Q&A 1 30th Mar 2009 08:08
Validations are not called when I use section in Dyanmic Form. kkumar Technical Q&A 5 12th Mar 2009 15:48

© 2010,2011 Isomorphic Software. All Rights Reserved