| 6 |
return { |
return { |
| 7 |
orientationValid : 'before', |
orientationValid : 'before', |
| 8 |
orientationError : 'before', |
orientationError : 'before', |
|
valid : '', |
|
| 9 |
validMessages : true, |
validMessages : true, |
| 10 |
errorNumeric : 'Numbers only.', |
errorNumeric : 'Numbers only.', |
| 11 |
errorEmail : 'Invalid email.', |
errorEmail : 'Invalid email.', |
| 14 |
* Initialize |
* Initialize |
| 15 |
*/ |
*/ |
| 16 |
init : function() { |
init : function() { |
| 17 |
|
// settings |
| 18 |
|
var settings = Drupal.settings.jsv; |
| 19 |
|
|
| 20 |
|
$.each(settings, function(i, e){ |
| 21 |
|
validator[i] = e; |
| 22 |
|
}); |
| 23 |
|
// event handlers |
| 24 |
$('.numeric').change(function(){ validator.numeric(this); }); |
$('.numeric').change(function(){ validator.numeric(this); }); |
| 25 |
$('.email').change(function(){ validator.email(this); }); |
$('.email').change(function(){ validator.email(this); }); |
| 26 |
$('.request').change(function(){ validator.request(this); }); |
$('.request').change(function(){ validator.request(this); }); |
| 29 |
/** |
/** |
| 30 |
* Display a valid message |
* Display a valid message |
| 31 |
*/ |
*/ |
| 32 |
validDisplay : function(input) { |
validDisplay : function(input, message) { |
| 33 |
// remove previous messages |
// remove previous messages |
| 34 |
validator.validRemove(input); |
validator.validRemove(input); |
| 35 |
validator.errorRemove(input); |
validator.errorRemove(input); |
| 36 |
if (validator.validMessages == true){ |
if (validator.validMessages == true && typeof message != 'undefined'){ |
| 37 |
// add messages |
// add messages |
| 38 |
switch(validator.orientationValid){ |
switch(validator.orientationValid){ |
| 39 |
case 'before': |
case 'before': |
| 40 |
$(input).before('<span class="validator-valid">' + validator.valid + '</span>'); |
$(input).before('<span class="validator-valid">' + message + '</span>'); |
| 41 |
break; |
break; |
| 42 |
|
|
| 43 |
case 'after': |
case 'after': |
| 44 |
$(input).after('<span class="validator-valid">' + validator.valid + '</span>'); |
$(input).after('<span class="validator-valid">' + message + '</span>'); |
| 45 |
break; |
break; |
| 46 |
} |
} |
|
$(input).addClass('validator-valid-input'); |
|
| 47 |
} |
} |
| 48 |
|
$(input).addClass('validator-valid-input'); |
| 49 |
}, |
}, |
| 50 |
|
|
| 51 |
/** |
/** |
| 173 |
if (validatorPath){ |
if (validatorPath){ |
| 174 |
$.getJSON(validatorPath + '/' + value, function(json){ |
$.getJSON(validatorPath + '/' + value, function(json){ |
| 175 |
if (json.valid){ |
if (json.valid){ |
| 176 |
validator.validDisplay(input); |
validator.validDisplay(input, json.message); |
| 177 |
} |
} |
| 178 |
else{ |
else{ |
| 179 |
validator.errorDisplay(input, json.message); |
validator.errorDisplay(input, json.message); |