Permalink
Browse files

Merge commit 'afdf1dad9743f88a603bce81f0602a8516815514' into HEAD

  • Loading branch information...
2 parents 67d8886 + afdf1da commit 7d18b134e42c7882a05a55421af2c6528030fd73 @joomla-jenkins joomla-jenkins committed Nov 13, 2012
Showing with 18 additions and 7 deletions.
  1. +3 −0 libraries/joomla/html/behavior.php
  2. +14 −0 media/system/js/validate-uncompressed.js
  3. +1 −7 media/system/js/validate.js
View
3 libraries/joomla/html/behavior.php
@@ -117,6 +117,9 @@ public static function formvalidation()
return;
}
+ // Add validate.js language strings
+ JText::script('JLIB_FORM_FIELD_INVALID');
+
// Include MooTools framework
self::framework();
View
14 media/system/js/validate-uncompressed.js
@@ -158,6 +158,20 @@ var JFormValidator = new Class({
}
});
+ if (!valid) {
+ var message = Joomla.JText._('JLIB_FORM_FIELD_INVALID');
+ var errors = jQuery("label.invalid");
+ var error = new Object();
+ error.error = new Array();
+ for (var i=0;i < errors.length; i++) {
+ var label = jQuery(errors[i]).text();
+ if (label != 'undefined') {
+ error.error[i] = message+label.replace("*", "");
+ }
+ }
+ Joomla.renderMessages(error);
+ }
+
return valid;
},
View
8 media/system/js/validate.js
@@ -1,10 +1,4 @@
/*
GNU General Public License version 2 or later; see LICENSE.txt
*/
-Object.append(Browser.Features,{inputemail:function(){var a=document.createElement("input");a.setAttribute("type","email");return a.type!=="text"}()});
-var JFormValidator=new Class({initialize:function(){this.handlers={};this.custom={};this.setHandler("username",function(a){regex=/[<|>|"|'|%|;|(|)|&]/i;return!regex.test(a)});this.setHandler("password",function(a){regex=/^\S[\S ]{2,98}\S$/;return regex.test(a)});this.setHandler("numeric",function(a){regex=/^(\d|-)?(\d|,)*\.?\d*$/;return regex.test(a)});this.setHandler("email",function(a){regex=/^[a-zA-Z0-9._-]+(\+[a-zA-Z0-9._-]+)*@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;return regex.test(a)});$$("form.form-validate").each(function(a){this.attachToForm(a)},
-this)},setHandler:function(a,b,c){this.handlers[a]={enabled:c==""?!0:c,exec:b}},attachToForm:function(a){a.getElements("input,textarea,select,button").each(function(a){a.hasClass("required")&&(a.set("aria-required","true"),a.set("required","required"));if((document.id(a).get("tag")=="input"||document.id(a).get("tag")=="button")&&document.id(a).get("type")=="submit"){if(a.hasClass("validate"))a.onclick=function(){return document.formvalidator.isValid(this.form)}}else if(a.addEvent("blur",function(){return document.formvalidator.validate(this)}),
-a.hasClass("validate-email")&&Browser.Features.inputemail)a.type="email"})},validate:function(a){a=document.id(a);if(a.get("disabled"))return this.handleResponse(!0,a),!0;if(a.hasClass("required"))if(a.get("tag")=="fieldset"&&(a.hasClass("radio")||a.hasClass("checkboxes")))for(var b=0;;b++)if(document.id(a.get("id")+b)){if(document.id(a.get("id")+b).checked)break}else return this.handleResponse(!1,a),!1;else if(!a.get("value"))return this.handleResponse(!1,a),!1;b=a.className&&a.className.search(/validate-([a-zA-Z0-9\_\-]+)/)!=
--1?a.className.match(/validate-([a-zA-Z0-9\_\-]+)/)[1]:"";if(b=="")return this.handleResponse(!0,a),!0;if(b&&b!="none"&&this.handlers[b]&&a.get("value")&&this.handlers[b].exec(a.get("value"))!=!0)return this.handleResponse(!1,a),!1;this.handleResponse(!0,a);return!0},isValid:function(a){for(var b=!0,a=a.getElements("fieldset").concat(Array.from(a.elements)),c=0;c<a.length;c++)this.validate(a[c])==!1&&(b=!1);(new Hash(this.custom)).each(function(a){a.exec()!=!0&&(b=!1)});return b},handleResponse:function(a,
-b){b.labelref||$$("label").each(function(a){if(a.get("for")==b.get("id"))b.labelref=a});a==!1?(b.addClass("invalid"),b.set("aria-invalid","true"),b.labelref&&(document.id(b.labelref).addClass("invalid"),document.id(b.labelref).set("aria-invalid","true"))):(b.removeClass("invalid"),b.set("aria-invalid","false"),b.labelref&&(document.id(b.labelref).removeClass("invalid"),document.id(b.labelref).set("aria-invalid","false")))}});document.formvalidator=null;
-window.addEvent("domready",function(){document.formvalidator=new JFormValidator});
+Object.append(Browser.Features,{inputemail:function(){var e=document.createElement("input");e.setAttribute("type","email");return e.type!=="text"}()});var JFormValidator=new Class({initialize:function(){this.handlers=Object();this.custom=Object();this.setHandler("username",function(e){regex=new RegExp("[<|>|\"|'|%|;|(|)|&]","i");return!regex.test(e)});this.setHandler("password",function(e){regex=/^\S[\S ]{2,98}\S$/;return regex.test(e)});this.setHandler("numeric",function(e){regex=/^(\d|-)?(\d|,)*\.?\d*$/;return regex.test(e)});this.setHandler("email",function(e){regex=/^[a-zA-Z0-9._-]+(\+[a-zA-Z0-9._-]+)*@([a-zA-Z0-9.-]+\.)+[a-zA-Z0-9.-]{2,4}$/;return regex.test(e)});var e=$$("form.form-validate");e.each(function(e){this.attachToForm(e)},this)},setHandler:function(e,t,n){n=n==""?true:n;this.handlers[e]={enabled:n,exec:t}},attachToForm:function(e){e.getElements("input,textarea,select,button").each(function(e){if(e.hasClass("required")){e.set("aria-required","true");e.set("required","required")}if((document.id(e).get("tag")=="input"||document.id(e).get("tag")=="button")&&document.id(e).get("type")=="submit"){if(e.hasClass("validate")){e.onclick=function(){return document.formvalidator.isValid(this.form)}}}else{e.addEvent("blur",function(){return document.formvalidator.validate(this)});if(e.hasClass("validate-email")&&Browser.Features.inputemail){e.type="email"}}})},validate:function(e){e=document.id(e);if(e.get("disabled")){this.handleResponse(true,e);return true}if(e.hasClass("required")){if(e.get("tag")=="fieldset"&&(e.hasClass("radio")||e.hasClass("checkboxes"))){for(var t=0;;t++){if(document.id(e.get("id")+t)){if(document.id(e.get("id")+t).checked){break}}else{this.handleResponse(false,e);return false}}}else if(!e.get("value")){this.handleResponse(false,e);return false}}var n=e.className&&e.className.search(/validate-([a-zA-Z0-9\_\-]+)/)!=-1?e.className.match(/validate-([a-zA-Z0-9\_\-]+)/)[1]:"";if(n==""){this.handleResponse(true,e);return true}if(n&&n!="none"&&this.handlers[n]&&e.get("value")){if(this.handlers[n].exec(e.get("value"))!=true){this.handleResponse(false,e);return false}}this.handleResponse(true,e);return true},isValid:function(e){var t=true;var n=e.getElements("fieldset").concat(Array.from(e.elements));for(var r=0;r<n.length;r++){if(this.validate(n[r])==false){t=false}}(new Hash(this.custom)).each(function(e){if(e.exec()!=true){t=false}});if(!t){var i=Joomla.JText._("JLIB_FORM_FIELD_INVALID");var s=jQuery("label.invalid");var o=new Object;o.error=new Array;for(var r=0;r<s.length;r++){var u=jQuery(s[r]).text();if(u!="undefined"){o.error[r]=i+u.replace("*","")}}Joomla.renderMessages(o)}return t},handleResponse:function(e,t){if(!t.labelref){var n=$$("label");n.each(function(e){if(e.get("for")==t.get("id")){t.labelref=e}})}if(e==false){t.addClass("invalid");t.set("aria-invalid","true");if(t.labelref){document.id(t.labelref).addClass("invalid");document.id(t.labelref).set("aria-invalid","true")}}else{t.removeClass("invalid");t.set("aria-invalid","false");if(t.labelref){document.id(t.labelref).removeClass("invalid");document.id(t.labelref).set("aria-invalid","false")}}}});document.formvalidator=null;window.addEvent("domready",function(){document.formvalidator=new JFormValidator})

0 comments on commit 7d18b13

Please sign in to comment.