0 Replies Latest reply: Nov 5, 2010 1:18 PM by Phil_W RSS

    Custom password validation fields

    Phil_W Community Member

      Hi,

       

      I was browsing the css for the password validation widget when I came across .passwordCustomMsg.  Great I thought a built in class to add a custom message to my password validation.

       

      I have a Ajax based Forum built entirely on Spry with a series of backed server side pages I have created to process and respond to the submissions from the Spry utilities.  It is almost ready for release and I just doing the final bits that allow a user to update their profile.  I have added Spry validation widgets to the page, but the backend server pages also make certain validations to ensure that only an authorised user is making the changes. On such check it that to update a user profile the user has to supply their current password. If the userid and password do not correctly retrieve a record from the backend members table of the database then the server page returns an error.  The Spry callback function then processes the response and if it indicates the error in the userid / password combination it add an error class to the current password field.  But I'm wondering if there is a built in function to indicate the customer error against the password field.  The code I've written is extracted  below but I wondered if the widget has a custom function to do the same, to make it more elegant.  My Spry  Password validation widget  js is packed so I can't read it directly to find out and the api documentation doesn't say. Don't worry about the alert in the callback function, it's not finished yet!

       

      <legend>Confirm Identity</legend>
        <span id="yourPassword">
        <label for="myPassword">Current password</label>
        <input name="myPassword" type="password" id="myPassword" size="60" maxlength="100" />
        <span class="passwordRequiredMsg">Your current password is required.</span>
         <span class="passwordCustomMsg">Supplied password is invalid.</span>
        </span>
        </fieldset>

       

      var sprypassword1 = new Spry.Widget.ValidationPassword("yourPassword",{isRequired:true});

       

      if (Spry.Widget.Form.validate(Spry.$$('#userProfileForm')[0]) == true)
          {
          myAvatar =  Spry.$$('#myAvatar img','TabbedPanels1')[0].getAttribute('src');
          Spry.Utils.submitForm('userProfileForm', updateProfileDiv, {method:'post',url:'serverside/updateProfile.asp',additionalData:myData});
         
          }

       

      function updateProfileDiv(req)
      {
          var mytext = req.xhRequest.responseText
          switch(mytext)
          {
           case "password invalid":
            Spry.$$('#yourPassword','TabbedPanels1').setAttribute('class','passwordCustomState');
           
            break;
          default:   
          alert(mytext);
          }
      }