[cgiapp] Data.FormValidator.js
Joshua Miller
unrtst at gmail.com
Mon Jan 26 11:43:17 EST 2009
Apologies if this has gone too far offtopic...
On Mon, Jan 26, 2009 at 6:40 AM, Lyle <webmaster at cosmicperl.com> wrote:
> Joshua,
> Have you managed to figure out a work around for:-
>
> 'constraints' => {
> 'password1' => {
> 'constraint' => "check_passwords",
> 'params' => [ qw( password1 password2 ) ],
> },
> },
> ...
> sub check_passwords {
> my ( $pw1, $pw2 ) = @_;
> if ( $pw1 eq $pw2 ) {
> return 1;
> } else {
> return 0;
> }
> }
>
Currently, there is no easy, built-in way to do this.
Many times, I'll just leave that up to the backend to handle. Of
course, it is possible to tie it in on the frontend. Take the
check_and_report function from the file Data/FormValidator.js, and
update the end part of it something like this:
if (! results.success()) {
...leave this stuff
} else {
// This is where you'd add the password eq check
// assuming the profile already checked password1 and password2
// had some valid value
var password1 = results.getField(frmObj, 'password1');
var password2 = results.getField(frmObj, 'password2');
if ( password1[0] != password2[0] ) {
results.changeStyle(frmObj, 'password1', badColor);
results.changeStyle(frmObj, 'password2', badColor);
alert("There is a problem with your form.\n\nThe entered
passwords do not match.");
return false
} else {
return true;
}
}
I would like to see Data.FormValidator.js get support for including
things like that in the profile. While it would break the profiles
compatibility with Data::FormValidator.pm, a filter could be
implemented to let the profile be used on both of them. I'm not
totally sure how that would work out though. At least for myself, I
usually generate the javascript profile from a profile written in
perl, and that would make it difficult to include a javascript
function definition inline.
I'm open to suggestions and patches, but that conversation should
probably be moved offlist or to the forum on the Data.FormValidator.js
berlios page.
Thanks,
--
Josh I.
More information about the cgiapp
mailing list