If you're puzzling over how to create the usual password and confirmation fields using Dojo, try out this approach that I came up with for a project I'm working on:
It's really simple and keeps everything lean, relying on as little implementation code as possible. Simply put, every time the password field changes, assign a new escaped validation string to the check field. It also makes sure to trigger a validation on the check field just in case there's already a value there.
While my example is programmatic, I'm sure there's a declarative equivalent that can be easily derived from my approach here.
I can only imagine how confusing some of the equivalent jQuery solutions to this problem are!
var passwordCheck = new ValidationTextBox({ id: "password-check", placeholder: "Password again...", type: "password", intermediateChanges: true, invalidMessage: "The value you have entered does not match the password you have chosen..." });
this.password = new ValidationTextBox({ name: "password", id: "password", placeholder: "Password...", type: "password", intermediateChanges: true, onChange: function () { passwordCheck.set("pattern", this.value.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"));
if(passwordCheck.value) { passwordCheck.validate(); }}});
It's really simple and keeps everything lean, relying on as little implementation code as possible. Simply put, every time the password field changes, assign a new escaped validation string to the check field. It also makes sure to trigger a validation on the check field just in case there's already a value there.
While my example is programmatic, I'm sure there's a declarative equivalent that can be easily derived from my approach here.
I can only imagine how confusing some of the equivalent jQuery solutions to this problem are!
Comments
Post a Comment