vendor/assets/javascripts/webshims/shims/form-validators.js in webshims-rails-1.12.3 vs vendor/assets/javascripts/webshims/shims/form-validators.js in webshims-rails-1.12.5

- old
+ new

@@ -91,10 +91,22 @@ } } return message; }; var testValidityRules = webshims.refreshCustomValidityRules; + + if(typeof document.activeElement != 'unknown'){ + $('body').on('click', function(e){ + if(e.target.type == 'submit'){ + var activeElement = document.activeElement; + + if(activeElement != e.target && $.data(activeElement, 'webshimsswitchvalidityclass')){ + $(activeElement).trigger('refreshvalidityui'); + } + } + }); + } webshims.ready('forms form-validation', function(){ $.propHooks.setCustomValidity = { get: function(elem){ @@ -262,16 +274,14 @@ if(data.prop !== "value" || specialVal){ $(data.masterElement.type === 'radio' && getGroupElements(data.masterElement) || data.masterElement).on('change', depFn); } else { $(data.masterElement).on('change', function(){ + webshims.refreshCustomValidityRules(elem); $(elem) .getShadowElement() .filter('.user-error, .user-success') - .each(function(){ - webshims.refreshCustomValidityRules(elem); - }) .trigger('refreshvalidityui') ; }); } } @@ -282,11 +292,17 @@ depFn(); return ''; } }, 'The value of this field does not repeat the value of the other field'); - - + + addCustomValidityRule('valuevalidation', function(elem, val, data){ + if(val && ('valuevalidation' in data)){ + //Todo allow markup params + return $(elem).triggerHandler('valuevalidation', [{value: val, valueAsDate: $.prop(elem, 'valueAsDate'), isPartial: false}]) || ''; + } + }, 'This value is not allowed here'); + if(window.JSON){ addCustomValidityRule('ajaxvalidate', function(elem, val, data){ if(!val || !data.ajaxvalidate){return;} var opts; if(!data.remoteValidate){