|
#11
|
|||
|
|||
|
So adding "^" at the beginning and "$" at the end would resolve my issue. Let me try and let you know.
Thanks for your help. |
|
#12
|
|||
|
|||
|
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})+)*(,)*$");
}
Please let me know what is the issue/is it a known issue? |
|
#13
|
|||
|
|||
|
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. |
|
#14
|
|||
|
|||
|
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);
}
}
|
|
#15
|
|||
|
|||
|
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.
|
![]() |
| Thread Tools | Search this Thread |
|
|
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 |