3 Replies Latest reply on Sep 7, 2007 7:37 AM by Jan Schneider

    a4j:support onSubmit not working

    Jan Schneider Newbie

      Hi,
      I'm new to ajax4jsf and have some trouble with the onsubmit attribute in the a4j:support tag.
      I have a text input field which includes an a4j:support tag. The characters entered by the user are displayed in an simple, ajax rendered output text tag.
      Using the onSubmit attribute of the a4j:support tag I want to call a custom JavaScript function that checks the length of the text input field. If the length is less than 3 the function returns false to prevent the AJAX Request from being fired, but it is always sent!?

      JavaScript function:
      function checkLength() {
      var length = document.getElementById("login_form:username").value.length;

      if(length < 3) {
      return false;
      }
      }


      JSF:
      <h:inputText binding="#{login.textInputUsername}"
      readonly="false" id="username" size="30" value="#{login.username}">
      <a4j:support event="onkeyup" reRender="repeater" onsubmit="checkLength()"/>
      </h:inputText>


      which is transformed into:
      <input id="login_form:username" type="text" name="login_form:username" onkeyup="checkLength();A4J.AJAX.Submit('.....

      The custom JavaScript function is called, and the length is also correct (thus less than 3 for the first two characters), but nevertheless the AJAX request is fired and the output text re-rendered.

      I think it is only a small mistake, but I just can't find it.
      Can anyone please help me!?

      Regards
      Jan