Announcement

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

    DynamicForm's hasErrors is inconsistent

    I'm using SmartGWTPower-2.3 and Firefox 3.6.8. This does not happen using I.E. 8

    I have a DynamicForm form, with a textItem, name, that must be unique to a specified table in the database on a remote server. That table is also represented in the form in a ListGrid. I define the validator in the ds.xml file:
    Code:
    <field name="name" length="51" type="text">
    	<validators>
    		<validator type="isUnique" requiresServer="true" />
    	</validators>
    </field>
    When I enter a duplicate name, the invalid icon appears next to the name textItem, as expected. Then I hit the Save button and before saving the form the code checks for validation errors by calling isValid().
    Code:
    public Boolean isValid(){
    	if (form.hasErrors()){
    		SC.logWarn("form.hasErrors is true");
    		return false;
    	}
    	SC.logWarn("form.hasErrors is false");
    	return true; 
    }
    Although the invalid icon is still displayed in the form, indicating an error, form.hasErrors() returns false. If I hit the Save button again, form.hasErrors() will return true, and continue to return true until I exit the current form.

    What causes the form.hasErrors() to return false on the first attempt?
    When using I.E. form.hasErrors() will return true everytime when there is an error on the form.

    #2
    What's the context for this isValid() method - how and where are you calling it?

    What this suggests is possible a timing issue in how you're calling this code. isUnique is an asynchronous validator since it involves a server trip. While the validation request is pending, hasErrors() is really neither true nor false. It's unclear how you could get inconsistent results in different browsers, but we'll have to understand the context of the call to isValid() before we can comment further.

    Comment


      #3
      This is how I validate.

      Code:
      name.addKeyUpHandler(new KeyUpHandler() {
      			@Override
      			public void onKeyUp(KeyUpEvent event) {
      				if (form.valuesHaveChanged()){
      				form.getItem(NAME_DS_FIELDNAME).validate();
      				}
      			}			
      		});
      This is where I save, which is triggered by the Save button. At this point the form display already shows that the textItem is invalid.
      Code:
      protected void saveChanges() {
      		if (isValid())
      			save();
      }
      This is how I save.
      Code:
      public void save() {
      	DSRequest requestProperties = new DSRequest();
      	requestProperties.setPrompt(constants.savingSalesRep());
      	form.saveData(new DSCallback() {
      		public void execute(DSResponse response, Object rawData, DSRequest request) {
      			Record[] records = response.getData();
      			currentRecord = records[0];
      			}
      		}, requestProperties);
      	
      	}
      I have this working for other forms in my application.

      Comment


        #4
        So far we haven't been able to reproduce this (we've been modifying this sample).

        Looking at the code, it seems like the only way you could be seeing an error message while hasErrors() is false is if the error message was null - if you hover over the error icon, are you seeing an error message displayed?

        Another possibility would be manual calls to clearFieldErrors() / clearErrors() / setFieldErrors() or similar. Have any calls like that?

        Comment


          #5
          Before and after hitting the Save button, when hovering over the error icon the message is "Value must be unique".

          I was using clearErrors. I removed it from the code, but it did not change the behavior of hasErrors. Still, the first time it is called it returns false. Then true each subsequent time until I enter a different duplicate name, at which time it returns false.

          Have you run it in Firefox?

          Comment


            #6
            Yes, we're seeing consistent behavior in all browsers after modifying a sample to be close to your stated scenario.

            Are you able to reproduce the behavior by modifying that sample? I think we're going to find that this is related to manual management of validation errors in some way.

            Comment


              #7
              Is there a sample from smartgwtpower-2.3? I don't have Enterprise.

              I tried using the files in the example, but I can't run it. I'm attaching only the first half of the Console output due to size limits.

              Thanks.
              Attached Files

              Comment


                #8
                Yes, that sample comes with your Power build, in the Showcase.

                It's not clear what steps you took to run the sample, but you've got totally unrelated errors in your logs - they don't have to do with an attempt to run the sample.

                Comment

                Working...
                X