[jQuery] Re: Individual Custom Message [validate]

2009-04-10 Thread dotcomtim

All three problems solved.

On Apr 9, 6:52 pm, dotcomtim dotcom...@hotmail.com wrote:
 Solved 1 and 2 just not the third. Anyway to detected duplicates only?
 Everything I found on the net only removes duplicates.

 $.validator.addMethod('keywords', function(value, element) {
         var valid = true;
         var valid = (value.length  0);
         var message = $(element);
         if (this.optional(element)) {
                 return true;
         }
         var keywords = value.split(',');
         for (var i in keywords) {
                 keyword = Trim(keywords[i]);
                 duplicates = Trim(keywords[i]);
                 if (!keywords[2]) {
                         message.parent('div').next('div').empty().append('3 
 required');
                         var valid = false;
                 }
                 else if (keywords[8]) {
                         message.parent('div').next('div').empty().append('8 
 to many.');
                         var valid = false;
                 }
                 if (keyword.length  3) {
                         message.parent('div').next('div').empty().append('3 
 characters
 minimum');
                         var valid = false;
                 }
                 else if (keyword.length  30) {
                         message.parent('div').next('div').empty().append('30 
 characters
 maximum');
                         var valid = false;
                 }
                 else if (keyword.match(/\b\w+\b/g).length  2) {
                         message.parent('div').next('div').empty().append('2 
 words in
 each');
                         var valid = false;
                 }
                 else {
                         var words = keyword.split(' ');
                         for (var i in words) {
                                 word = Trim(words[i]);
                                 if (word.length  3) {
                                         
 message.parent('div').next('div').empty().append('each word 3
 characters minimum');
                                         var valid = false;
                                 }
                         }
                 }
         }
         return valid;

 }, false);

 On Apr 9, 10:51 am, dotcomtim dotcom...@hotmail.com wrote:

  I am working on a custom filter to check for errors by adding the
  addMethod() function within the jQuery Validation Plugin. I have
  success so far with most of it except for the last few items.

  1) Individual Messages – I like to replace the alert messages to
  append their own message. I tried several methods according to the
  plugin except I keep getting this error Warning: No message defined
  for keywords. I can eliminate this by adding a common error message
  for keywords except I am looking for individual messages.

  Here is what I have add success with so far.
  $.validator.addMethod(keywords, function(value, element) {
          if (this.optional(element)) {
                  return true;
          }
          var valid = true;
          var keywords = value.split(',');
          var valid = (value.length  0);
          for (var i in keywords) {
                  keyword = Trim(keywords[i]);
                  if (keyword.length  3) {
                          //alert('to short '+keyword);
                          var valid = false;
                  }
                  else if (keyword.length  30) {
                          //alert('to long '+keyword);
                          var valid = false;
                  }
                  else if (keyword.match(/\b\w+\b/g).length  2) {
                          //alert('to many words '+keyword);
                          var valid = false;
                  }
                  // else if (duplicates) { }
                  // else if (each word greater than 2 characters) {}
          }
          return valid;

  });

  If I can get help with item 1 I would appreciate it allot. Items 2 and
  3 are not important unless someone has done something similar I give
  suggestions.

  2) Validate duplicate words – If 2 keywords are the same fire off an
  error.

  Allow Example: water, waterfront
  Disallowed Example: waterfront, waterfront

  3) Validate character length in each word – If an individual word is
  less than 3 characters fire off an error.

  Allow Example: the waterfront
  Disallowed Example: a waterfront


[jQuery] Individual Custom Message [validate]

2009-04-09 Thread dotcomtim

I am working on a custom filter to check for errors by adding the
addMethod() function within the jQuery Validation Plugin. I have
success so far with most of it except for the last few items.

1) Individual Messages – I like to replace the alert messages to
append their own message. I tried several methods according to the
plugin except I keep getting this error Warning: No message defined
for keywords. I can eliminate this by adding a common error message
for keywords except I am looking for individual messages.

Here is what I have add success with so far.
$.validator.addMethod(keywords, function(value, element) {
if (this.optional(element)) {
return true;
}
var valid = true;
var keywords = value.split(',');
var valid = (value.length  0);
for (var i in keywords) {
keyword = Trim(keywords[i]);
if (keyword.length  3) {
//alert('to short '+keyword);
var valid = false;
}
else if (keyword.length  30) {
//alert('to long '+keyword);
var valid = false;
}
else if (keyword.match(/\b\w+\b/g).length  2) {
//alert('to many words '+keyword);
var valid = false;
}
// else if (duplicates) { }
// else if (each word greater than 2 characters) {}
}
return valid;
});

If I can get help with item 1 I would appreciate it allot. Items 2 and
3 are not important unless someone has done something similar I give
suggestions.


2) Validate duplicate words – If 2 keywords are the same fire off an
error.

Allow Example: water, waterfront
Disallowed Example: waterfront, waterfront


3) Validate character length in each word – If an individual word is
less than 3 characters fire off an error.

Allow Example: the waterfront
Disallowed Example: a waterfront


[jQuery] Re: Individual Custom Message [validate]

2009-04-09 Thread dotcomtim

Solved 1 and 2 just not the third. Anyway to detected duplicates only?
Everything I found on the net only removes duplicates.

$.validator.addMethod('keywords', function(value, element) {
var valid = true;
var valid = (value.length  0);
var message = $(element);
if (this.optional(element)) {
return true;
}
var keywords = value.split(',');
for (var i in keywords) {
keyword = Trim(keywords[i]);
duplicates = Trim(keywords[i]);
if (!keywords[2]) {
message.parent('div').next('div').empty().append('3 
required');
var valid = false;
}
else if (keywords[8]) {
message.parent('div').next('div').empty().append('8 to 
many.');
var valid = false;
}
if (keyword.length  3) {
message.parent('div').next('div').empty().append('3 
characters
minimum');
var valid = false;
}
else if (keyword.length  30) {
message.parent('div').next('div').empty().append('30 
characters
maximum');
var valid = false;
}
else if (keyword.match(/\b\w+\b/g).length  2) {
message.parent('div').next('div').empty().append('2 
words in
each');
var valid = false;
}
else {
var words = keyword.split(' ');
for (var i in words) {
word = Trim(words[i]);
if (word.length  3) {

message.parent('div').next('div').empty().append('each word 3
characters minimum');
var valid = false;
}
}
}
}
return valid;
}, false);

On Apr 9, 10:51 am, dotcomtim dotcom...@hotmail.com wrote:
 I am working on a custom filter to check for errors by adding the
 addMethod() function within the jQuery Validation Plugin. I have
 success so far with most of it except for the last few items.

 1) Individual Messages – I like to replace the alert messages to
 append their own message. I tried several methods according to the
 plugin except I keep getting this error Warning: No message defined
 for keywords. I can eliminate this by adding a common error message
 for keywords except I am looking for individual messages.

 Here is what I have add success with so far.
 $.validator.addMethod(keywords, function(value, element) {
         if (this.optional(element)) {
                 return true;
         }
         var valid = true;
         var keywords = value.split(',');
         var valid = (value.length  0);
         for (var i in keywords) {
                 keyword = Trim(keywords[i]);
                 if (keyword.length  3) {
                         //alert('to short '+keyword);
                         var valid = false;
                 }
                 else if (keyword.length  30) {
                         //alert('to long '+keyword);
                         var valid = false;
                 }
                 else if (keyword.match(/\b\w+\b/g).length  2) {
                         //alert('to many words '+keyword);
                         var valid = false;
                 }
                 // else if (duplicates) { }
                 // else if (each word greater than 2 characters) {}
         }
         return valid;

 });

 If I can get help with item 1 I would appreciate it allot. Items 2 and
 3 are not important unless someone has done something similar I give
 suggestions.

 2) Validate duplicate words – If 2 keywords are the same fire off an
 error.

 Allow Example: water, waterfront
 Disallowed Example: waterfront, waterfront

 3) Validate character length in each word – If an individual word is
 less than 3 characters fire off an error.

 Allow Example: the waterfront
 Disallowed Example: a waterfront


[jQuery] [validate] one form multiple validations

2008-10-03 Thread dotcomtim

In the validation plugin I am using rules and messages to validate a
one form which is broken up into multiple steps within the one form.
Similar to this script http://jquery.bassistance.de/validate/demo/multipart/
but altered to add custom rules and messages. Here is what I have so
far.


$(document).ready(function() {
var v = $('#form').validate({
errorPlacement: function(error, element) {
error.appendTo(element.parent('div').next('div'));
},
rules: {
// validate step one
name: {
required: true
},
company: {
required: true
},
designation: {
required: true
},
address: {
required: true
},
city: {
required: true
},
province: {
required: true
},
postal: {
required: true
},
phone: {
required: true
},
// validate step two
user_name: {
required: true,
minlength: 3,
remote: 'get.php?do=checkName'
},
password: {
minlength: 5
},
password_confirm: {
minlength: 5,
equalTo: '#password'
}
},
messages: {
name: {required: 'A first and last name is required.'},
company: {required: 'A company name is required.'},
designation: {required: 'A designation is required.'},
address: {required: 'A mailing address is required.'},
city: {required: 'A town or city is required.'},
province: {required: 'A province is required.'},
postal: {required: 'A postal code is required.'},
phone: {required: 'A phone number is required.'},
email: {required: 'A valid email address is required.'},
user_name: {required: 'A user name is required.', 
minlength:
jQuery.format('A user name should be greater than {0} characters.'),
remote: jQuery.format('The user name {0} is already taken.')},
password: {rangelength: jQuery.format('Enter at least 
{0}
characters.')},
password_confirm: {minlength: jQuery.format('Enter at 
least {0}
characters.'), equalTo: 'Enter the same password as above.'}
}
});

$(#step2 .prevbttn).click(function(){
$(#step2).hide();
$(#step1).fadeIn(fast);
});

$(#step3 .prevbttn).click(function(){
$(#step3).hide();
$(#step2).fadeIn(fast);
});

$(.open2).click(function() {
if (v.form()) {
$(#step2).hide();
$(#step3).fadeIn(fast);
}
});

$(.open1).click(function() {
if (v.form()) {
$(#step1).hide();
$(#step2).fadeIn(fast);
}
});
});

In step one div I have all the step one fields div id=step1step
one fields/div
In step two div I have all the step two fields div id=step2step
two fields/div

I if I was to use this without the steps everything works perfect,
with the steps in validates step and even though step two is hidden it
still wants to validate it as well.

Is it possible to validate one form in mulitple sections? I tried the
remove funtion, I tried altering the multipart script but it seems it
works based on the accordian plugin and error messages not being
incorparated like I have above.

Can we when click on a button input type=button name=formNext1
id=formNext1 value=Next class=open1 formbttn / only validate a
section. input type=button name=formNext2 id=formNext2
value=Next class=open2 formbttn / validate another section?


[jQuery] JQuery Validation Script within a Step Wizard Script

2008-10-01 Thread dotcomtim

I like to incorporate the Validation scripting into a Step Wizard
http://worcesterwideweb.com/jquery/wizard/; I got it pretty much
licked except the section where it only validates the available step
and ignores the others.

I pretty much followed the same layout as in this demo 
http://jquery.bassistance.de/validate/demo/multipart/ the part I am
getting confused with is how it is determining the index in the match
function. Is this part of the validate scripting or found in the
accordion scripting?

Has anyone successfully merged the 2 together?
http://jquery.bassistance.de/validate/ and 
http://worcesterwideweb.com/jquery/wizard/

Any help would be much appropriated.