From bfe44c7741ac0d297357eb1d7e5de4719aee37c0 Mon Sep 17 00:00:00 2001 From: Adam Becker Date: Thu, 21 Mar 2013 17:21:38 -0700 Subject: [PATCH] Override value using data-value attribute --- dist/parsley-standalone.min.js | 2 +- dist/parsley.min.js | 2 +- parsley.js | 10 +++++----- tests/index.html | 3 +++ tests/tests.js | 15 +++++++++++++++ 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/dist/parsley-standalone.min.js b/dist/parsley-standalone.min.js index b5621de29..687d7b112 100644 --- a/dist/parsley-standalone.min.js +++ b/dist/parsley-standalone.min.js @@ -65,7 +65,7 @@ c},addMessage:function(a,c,b){if("undefined"!==typeof b&&!0===b)this.messages.ty typeof c&&this.bindValidationEvents()},updateConstraint:function(a,c){for(var b in a)this.updtConstraint({name:b,requirements:a[b],valid:null},c)},updtConstraint:function(a,c){this.constraints[a.name]=b.extend(!0,this.constraints[a.name],a);"string"===typeof c&&(this.Validator.messages[a.name]=c);this.bindValidationEvents()},removeConstraint:function(a){a=a.toLowerCase();delete this.constraints[a];"required"===a&&(this.isRequired=!1);this.hasConstraints()?this.bindValidationEvents():"ParsleyForm"=== typeof this.getParent()?this.getParent().removeItem(this.$element):this.destroy()},addCustomConstraintMessage:function(a){var c=a+("type"===a&&"undefined"!==typeof this.options[a]?this.options[a].charAt(0).toUpperCase()+this.options[a].substr(1):"")+"Message";"undefined"!==typeof this.options[c]&&this.Validator.addMessage("type"===a?this.options[a]:a,this.options[c],"type"===a)},bindValidationEvents:function(){this.valid=null;this.$element.addClass("parsley-validated");this.$element.off("."+this.type); this.options.remote&&!/change/i.test(this.options.trigger)&&(this.options.trigger=!this.options.trigger?"change":" change");var a=(!this.options.trigger?"":this.options.trigger)+(/key/i.test(this.options.trigger)?"":" keyup");this.$element.is("select")&&(a+=/change/i.test(a)?"":" change");a=a.replace(/^\s+/g,"").replace(/\s+$/g,"");this.$element.on((a+" ").split(" ").join("."+this.type+" "),!1,b.proxy(this.eventValidation,this))},generateHash:function(){return"parsley-"+(Math.random()+"").substring(2)}, -getHash:function(){return this.hash},getVal:function(){return this.$element.val()},eventValidation:function(a){var c=this.getVal();if("keyup"===a.type&&!/keyup/i.test(this.options.trigger)&&!this.validatedOnce||"change"===a.type&&!/change/i.test(this.options.trigger)&&!this.validatedOnce||!this.isRadioOrCheckbox&&c.length + + +
diff --git a/tests/tests.js b/tests/tests.js index d855a1adb..e4b26bc30 100644 --- a/tests/tests.js +++ b/tests/tests.js @@ -563,6 +563,21 @@ var testSuite = function () { } ) } ) + /*************************************** + override value with data-value + ***************************************/ + describe ( 'Override value with data-value' , function () { + it ( 'required - data-value is empty, value is empty', function () { + triggerSubmitValidation( '#datavalue1', '' ); + expect( $( '#datavalue1' ).hasClass( 'parsley-error' ) ).to.be( true ); + expect( getErrorMessage( '#datavalue1', 'required') ).to.be( 'This value is required.' ); + } ) + it ( 'required - data-value has value, value is empty', function () { + triggerSubmitValidation( '#datavalue2', '' ); + expect( $( '#datavalue2' ).hasClass( 'parsley-success' ) ).to.be( true ); + } ) + } ) + /*************************************** test options changes ***************************************/