Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    Async Custom Validator for TextItem

    Hey guys,

    Is there a way to create an async custom validator?

    I found an asny validation for the whole form, but as far as I understood it rlly is only for the whole form.
    http://forums.smartclient.com/showthread.php?t=19145&highlight=asynchronous+validation


    In my case I have a form and in the first Textfield the user should input some data, if the field loses focus (setValidateOnExit) I'm going to check if the input is valid and prefill some of the following fields.

    Since the upper approach is validating the whole form many fields would show errors even if the user didn't reach them yet.

    thx in advance,
    JC

    #2
    Hi JCarlson,

    while this is not validating, you could solve your pre-fill case with an addEditorExitHandler. I'm doing a similar thing:
    Code:
    addEditorExitHandler(new EditorExitHandler() {
    	@Override
    	public void onEditorExit(EditorExitEvent event) {
    		if (ComboBoxItemZipcode.this.getValueAsString() != null && !ComboBoxItemZipcode.this.getValueAsString().isEmpty()) {
    			zipcodeDS.fetchData(new AdvancedCriteria() {
    				{
    					buildCriterionFromList(OperatorId.AND,
    							new Criterion[] { new Criterion("COUNTRY_ID", OperatorId.EQUALS, selectedCountry.getValueAsString()),
    									new Criterion("ZIPCODE", OperatorId.EQUALS, ComboBoxItemZipcode.this.getValueAsString()) });
    				}
    			}, new DSCallback() {
    				@Override
    				public void execute(DSResponse dsResponse, Object data, DSRequest dsRequest) {
    					// Pre-fill the name of the city.
    					if (Helper.oneRow(dsResponse)) {
    						if (city != null && (city.getValue() == null || city.getValueAsString().isEmpty()))
    							city.setValue(dsResponse.getDataAsRecordList().first().getAttributeAsString("SUGGESTION"));
    
    					}
    ...
    ...
    Perhaps you can also use a onChange or onChanged handler.

    Best regards
    Blama

    Comment


      #3
      Hey Blama,

      Thx for this workaround, should fit my needs :)
      If I remember right there is a field.validate(); function, so the validation part can be done inside the onExitHandler.

      Cheers,
      JC

      Comment


        #4
        See the "serverCustom" ValidatorType.

        Comment

        Working...
        X