diff --git a/bower.json b/bower.json index a0df44c..966ac7b 100644 --- a/bower.json +++ b/bower.json @@ -1,6 +1,6 @@ { "name": "jquery-validation-unobtrusive-extensions", - "version": "1.0.1", + "version": "1.0.2", "homepage": "https://github.com/MvcControlsToolkit/Unobtrusive.Extensions", "description": "Add-on to jQuery Unobtrusive Validation to enable globalization and dynamic content parsing", "main": [ diff --git a/jquery.validate.unobtrusive.dynamic.js b/jquery.validate.unobtrusive.dynamic.js index 4b49e4d..aa24a52 100644 --- a/jquery.validate.unobtrusive.dynamic.js +++ b/jquery.validate.unobtrusive.dynamic.js @@ -41,9 +41,10 @@ $.validator.unobtrusive.parseDynamic = function (selector) { var form = $(selector).first().closest('form'); - if (form.length == 0) return; + if (!form.length && !$(selector).find('form').length) return; $.validator.unobtrusive.parse(selector); - registerFormFix(selector, form); + if (form.length) + registerFormFix(selector, form); } $.validator.unobtrusive.parseElementDynamic = function (selector) { var form = $(selector).first().closest('form'); diff --git a/jquery.validate.unobtrusive.dynamic.min.js b/jquery.validate.unobtrusive.dynamic.min.js index 6d670da..adcc4c6 100644 --- a/jquery.validate.unobtrusive.dynamic.min.js +++ b/jquery.validate.unobtrusive.dynamic.min.js @@ -1 +1 @@ -!function(e){function a(e,a){var o=a[0];o._mvcct_form_expando_||(o._mvcct_form_expando_=!0,n.push(a),1==n.length&&setTimeout(function(){for(;n.length;){var e=n.pop();e[0]._mvcct_form_expando_=!1,t(e),e.removeData("unobtrusiveValidation")}}))}function t(a){var t=a.data("unobtrusiveValidation");if(t){var n=a.validate();e.each(t.options.rules,function(a,o){if(void 0==n.settings.rules[a]){var i={};e.extend(i,o),i.messages=t.options.messages[a],e('[name= "'+a+'"]').rules("add",i)}else e.each(o,function(o,i){if(void 0==n.settings.rules[a][o]){var r={};r[o]=i,r.messages=t.options.messages[a][o],e('[name= "'+a+'"]').rules("add",r)}})})}}var n=[];e.validator.unobtrusive.parseDynamic=function(t){var n=e(t).first().closest("form");0!=n.length&&(e.validator.unobtrusive.parse(t),a(t,n))},e.validator.unobtrusive.parseElementDynamic=function(t){var n=e(t).first().closest("form");0!=n.length&&(e.validator.unobtrusive.parseElement(t,!0),a(t,n))};var o=window.mvcct||{},i=o.enhancer;i&&i.register(function(a,t){t?e.validator.unobtrusive.parse(document):e.validator.unobtrusive.parseDynamic(a)},!0,null,"unobtrusive validation")}(jQuery); \ No newline at end of file +!function(e){function n(e,n){var o=n[0];o._mvcct_form_expando_||(o._mvcct_form_expando_=!0,a.push(n),1==a.length&&setTimeout(function(){for(;a.length;){var e=a.pop();e[0]._mvcct_form_expando_=!1,t(e),e.removeData("unobtrusiveValidation")}}))}function t(n){var t=n.data("unobtrusiveValidation");if(t){var a=n.validate();e.each(t.options.rules,function(n,o){if(void 0==a.settings.rules[n]){var i={};e.extend(i,o),i.messages=t.options.messages[n],e('[name= "'+n+'"]').rules("add",i)}else e.each(o,function(o,i){if(void 0==a.settings.rules[n][o]){var r={};r[o]=i,r.messages=t.options.messages[n][o],e('[name= "'+n+'"]').rules("add",r)}})})}}var a=[];e.validator.unobtrusive.parseDynamic=function(t){var a=e(t).first().closest("form");(a.length||e(t).find("form").length)&&(e.validator.unobtrusive.parse(t),a.length&&n(t,a))},e.validator.unobtrusive.parseElementDynamic=function(t){var a=e(t).first().closest("form");0!=a.length&&(e.validator.unobtrusive.parseElement(t,!0),n(t,a))};var o=window.mvcct||{},i=o.enhancer;i&&i.register(function(n,t){t?e.validator.unobtrusive.parse(document):e.validator.unobtrusive.parseDynamic(n)},!0,null,"unobtrusive validation")}(jQuery); \ No newline at end of file diff --git a/jquery.validate.unobtrusive.extensions.min.js b/jquery.validate.unobtrusive.extensions.min.js index 4240f20..bd20a53 100644 --- a/jquery.validate.unobtrusive.extensions.min.js +++ b/jquery.validate.unobtrusive.extensions.min.js @@ -1 +1 @@ -!function(n){function e(n,e){var a=e[0];a._mvcct_form_expando_||(a._mvcct_form_expando_=!0,t.push(e),1==t.length&&setTimeout(function(){for(;t.length;){var n=t.pop();n[0]._mvcct_form_expando_=!1,r(n),n.removeData("unobtrusiveValidation")}}))}function r(e){var r=e.data("unobtrusiveValidation");if(r){var t=e.validate();n.each(r.options.rules,function(e,a){if(void 0==t.settings.rules[e]){var u={};n.extend(u,a),u.messages=r.options.messages[e],n('[name= "'+e+'"]').rules("add",u)}else n.each(a,function(a,u){if(void 0==t.settings.rules[e][a]){var l={};l[a]=u,l.messages=r.options.messages[e][a],n('[name= "'+e+'"]').rules("add",l)}})})}}var t=[];n.validator.unobtrusive.parseDynamic=function(r){var t=n(r).first().closest("form");0!=t.length&&(n.validator.unobtrusive.parse(r),e(r,t))},n.validator.unobtrusive.parseElementDynamic=function(r){var t=n(r).first().closest("form");0!=t.length&&(n.validator.unobtrusive.parseElement(r,!0),e(r,t))};var a=window.mvcct||{},u=a.enhancer;u&&u.register(function(e,r){r?n.validator.unobtrusive.parse(document):n.validator.unobtrusive.parseDynamic(e)},!0,null,"unobtrusive validation")}(jQuery),function(n){function e(n){return parseInt(n.attr("data-val-correcttype-type"))+(n.attr("data-is-range")||"range"==n.attr("type")?10:0)}function r(e,t){var a=e.name,u=null,l=a.lastIndexOf(".");if(0>l?u=t:r=a.substring(0,l+1)+t,!r)return null;var i=n("[name='"+u+"']");return i.length>0?i[0]:null}function t(n,e){if(!e)return[];e=e.split(" ");for(var t=[],a=0;a=u?l.setDate(a.getDate()-a.getDay()+1):l.setDate(a.getDate()+8-a.getDay()),l}function u(n){if(!x){var e=f.Globalize();s||(s=o.enhancer.getSupport().Html5InputSupport);var r=e.locale().attributes.language,t=e.cldr.get("main/"+r).numbers["symbols-numberSystem-latn"];m=s.number>2?new RegExp("^[+-.0-9]*$"):new RegExp("^[\\"+t.plusSign+"\\"+t.minusSign+"\\"+t.decimal+"0-9]*$"),c=s.range>2?new RegExp("^[+-.0-9]*$"):new RegExp("^[\\"+t.plusSign+"\\"+t.minusSign+"\\"+t.decimal+"0-9]*$"),v=e.dateParser({raw:"HH:mm:ss"}),d=e.dateParser({raw:"yyyy-MM-ddTHH:mm:ss"}),p=e.dateParser({raw:"yyyy-MM"}),g=s.week>2?function(n){return n}:a,y=s.week>2?function(n){return n}:function(n){return f.parse("week",n)},weekFormatter=s.week>2?function(n){return n}:function(n){return f.format("week",n)},w=function(n,e){return n?e?n+parseFloat(e):n:null},h=function(n,e){return n?e?new Date(n.getTime()+parseInt(e)):n:null};var u=document.createElement("INPUT");u.setAttribute("type","week"),b=s.week>2?function(n,e){if(!n)return null;if(!e)return n;var r=parseInt(e)/6048e5;return 0==r?n:(u.value=n,r>0?u.stepUp(r):u.stepDown(-r),u.value)}:h,E[0]=function(n){return n},k[0]=E[0],_[0]=function(n){return n},I[0]=E[0],E[1]=E[2]=E[3]=function(n){return f.parse("number",n)},k[1]=k[2]=k[3]=D,_[1]=_[2]=_[3]=w,I[1]=I[2]=I[3]=function(n){return f.format("number",n)},E[11]=E[12]=E[13]=function(n){return f.parse("range",n)},k[11]=k[12]=k[13]=D,_[11]=_[12]=_[13]=w,I[11]=I[12]=I[13]=function(n){return f.format("range",n)},E[4]=function(n){return f.parse("time",n)},k[4]=v,I[4]=function(n){return f.format("time",n)},E[5]=function(n){return f.parse("date",n)},k[5]=d,I[5]=function(n){return f.format("date",n)},E[6]=function(n){return f.parse("datetime",n)},k[6]=d,_[4]=_[5]=_[6]=h,I[6]=function(n){return f.format("datetime",n)},E[7]=y,k[7]=g,_[7]=b,I[7]=weekFormatter,E[8]=function(n){return f.parse("month",n)},k[8]=p,_[8]=h,I[8]=function(n){return f.format("month",n)},x=!0}}function l(n,e,r){n.rules[e]=r,n.message&&(n.messages[e]=n.message)}function i(e,r,t){if(r)for(var a=0;am&&n(t).val(I[l](c)),!0}return i(r)>=s(a[0])},n.validator.methods.maxE=function(r,t,a){f||u();var l=e(n(t));if(!r)return!0;var i=E[l],o=a[1];if(o&&n(t).is(":focus"))return!0;var s=k[l];if(o){var m=i(r),c=s(a[0]);return m>c&&n(t).val(I[l](c)),!0}return i(r)<=s(a[0])},n.validator.methods.rangeE=function(r,t,a){f||u();var l=e(n(t));if(!r)return!0;var i=E[l],o=a[2];if(o&&n(t).is(":focus"))return!0;var s=k[l];if(o){var m=i(r),c=s(a[0]);return c>m?n(t).val(I[l](c)):(c=s(a[1]),m>c&&n(t).val(I[l](c))),!0}return i(r)<=s(a[1])&&i(r)>=s(a[0])},n.validator.methods.correcttype=function(r,t,a){if(f||u(),!r)return!0;var l=e(n(t)),i=E[l],o=i(r);return(o||0===o)&&(!("number"==typeof o)||(10>l?m.test(r):c.test(r)))&&(1!=l&&2!=l&&11!=l&&12!=l||o%1===0)&&(1!=l&&11!=l||o>=0)},n.validator.methods.drange=function(r,t,a){if(f||u(),!r)return!0;var l=e(n(t)),i=a[0],o=a[1],s=a[2],m=a[3],c=a[4];if(c&&n(t).is(":focus"))return!0;for(var v,d,p,g,y,h=E[l],b=_[l],w=h(r),x=0;x=D||(v=D),D>w))){if(!c)return!1;p=!0,y=!0}}for(var x=0;x=d||(d=D),w>D))){if(!c)return!1;p=!0,g=!0}}if(c&&p){if(v>d)return!1;g?n(t).val(I[l](d)):y&&n(t).val(I[l](v))}return!0};var S=M.unobtrusive.adapters,R=0;for(R=0;Rl?u=t:r=a.substring(0,l+1)+t,!r)return null;var i=n("[name='"+u+"']");return i.length>0?i[0]:null}function t(n,e){if(!e)return[];e=e.split(" ");for(var t=[],a=0;a=u?l.setDate(a.getDate()-a.getDay()+1):l.setDate(a.getDate()+8-a.getDay()),l}function u(n){if(!x){var e=f.Globalize();s||(s=o.enhancer.getSupport().Html5InputSupport);var r=e.locale().attributes.language,t=e.cldr.get("main/"+r).numbers["symbols-numberSystem-latn"];m=s.number>2?new RegExp("^[+-.0-9]*$"):new RegExp("^[\\"+t.plusSign+"\\"+t.minusSign+"\\"+t.decimal+"0-9]*$"),c=s.range>2?new RegExp("^[+-.0-9]*$"):new RegExp("^[\\"+t.plusSign+"\\"+t.minusSign+"\\"+t.decimal+"0-9]*$"),v=e.dateParser({raw:"HH:mm:ss"}),d=e.dateParser({raw:"yyyy-MM-ddTHH:mm:ss"}),p=e.dateParser({raw:"yyyy-MM"}),g=s.week>2?function(n){return n}:a,h=s.week>2?function(n){return n}:function(n){return f.parse("week",n)},weekFormatter=s.week>2?function(n){return n}:function(n){return f.format("week",n)},w=function(n,e){return n?e?n+parseFloat(e):n:null},y=function(n,e){return n?e?new Date(n.getTime()+parseInt(e)):n:null};var u=document.createElement("INPUT");u.setAttribute("type","week"),b=s.week>2?function(n,e){if(!n)return null;if(!e)return n;var r=parseInt(e)/6048e5;return 0==r?n:(u.value=n,r>0?u.stepUp(r):u.stepDown(-r),u.value)}:y,E[0]=function(n){return n},k[0]=E[0],_[0]=function(n){return n},I[0]=E[0],E[1]=E[2]=E[3]=function(n){return f.parse("number",n)},k[1]=k[2]=k[3]=D,_[1]=_[2]=_[3]=w,I[1]=I[2]=I[3]=function(n){return f.format("number",n)},E[11]=E[12]=E[13]=function(n){return f.parse("range",n)},k[11]=k[12]=k[13]=D,_[11]=_[12]=_[13]=w,I[11]=I[12]=I[13]=function(n){return f.format("range",n)},E[4]=function(n){return f.parse("time",n)},k[4]=v,I[4]=function(n){return f.format("time",n)},E[5]=function(n){return f.parse("date",n)},k[5]=d,I[5]=function(n){return f.format("date",n)},E[6]=function(n){return f.parse("datetime",n)},k[6]=d,_[4]=_[5]=_[6]=y,I[6]=function(n){return f.format("datetime",n)},E[7]=h,k[7]=g,_[7]=b,I[7]=weekFormatter,E[8]=function(n){return f.parse("month",n)},k[8]=p,_[8]=y,I[8]=function(n){return f.format("month",n)},x=!0}}function l(n,e,r){n.rules[e]=r,n.message&&(n.messages[e]=n.message)}function i(e,r,t){if(r)for(var a=0;am&&n(t).val(I[l](c)),!0}return i(r)>=s(a[0])},n.validator.methods.maxE=function(r,t,a){f||u();var l=e(n(t));if(!r)return!0;var i=E[l],o=a[1];if(o&&n(t).is(":focus"))return!0;var s=k[l];if(o){var m=i(r),c=s(a[0]);return m>c&&n(t).val(I[l](c)),!0}return i(r)<=s(a[0])},n.validator.methods.rangeE=function(r,t,a){f||u();var l=e(n(t));if(!r)return!0;var i=E[l],o=a[2];if(o&&n(t).is(":focus"))return!0;var s=k[l];if(o){var m=i(r),c=s(a[0]);return c>m?n(t).val(I[l](c)):(c=s(a[1]),m>c&&n(t).val(I[l](c))),!0}return i(r)<=s(a[1])&&i(r)>=s(a[0])},n.validator.methods.correcttype=function(r,t,a){if(f||u(),!r)return!0;var l=e(n(t)),i=E[l],o=i(r);return(o||0===o)&&(!("number"==typeof o)||(10>l?m.test(r):c.test(r)))&&(1!=l&&2!=l&&11!=l&&12!=l||o%1===0)&&(1!=l&&11!=l||o>=0)},n.validator.methods.drange=function(r,t,a){if(f||u(),!r)return!0;var l=e(n(t)),i=a[0],o=a[1],s=a[2],m=a[3],c=a[4];if(c&&n(t).is(":focus"))return!0;for(var v,d,p,g,h,y=E[l],b=_[l],w=y(r),x=0;x=D||(v=D),D>w))){if(!c)return!1;p=!0,h=!0}}for(var x=0;x=d||(d=D),w>D))){if(!c)return!1;p=!0,g=!0}}if(c&&p){if(v>d)return!1;g?n(t).val(I[l](d)):h&&n(t).val(I[l](v))}return!0};var S=M.unobtrusive.adapters,R=0;for(R=0;R