From 5ad959aeec1bcac98e96f07f0c183aef74fffd4d Mon Sep 17 00:00:00 2001 From: Eduardo Arino de la Rubia Date: Fri, 9 Nov 2012 15:08:35 -0800 Subject: [PATCH 1/2] Updated Cakefile so it would not complain about out of support stuff, added a test in Focus.Spec.js and then added feature to masked method to allow the passing in of a new option, retainPartial. This should allow for better integration with the jquery validate library, as previously on partially entered data, the field would clear before jQuery Validate had a chance to even test the field's partial value for any sort of correctness. --- Cakefile | 4 ++-- spec/Focus.Spec.js | 26 ++++++++++++++++++++++++++ src/jquery.maskedinput.js | 6 ++++-- 3 files changed, 32 insertions(+), 4 deletions(-) diff --git a/Cakefile b/Cakefile index d91b6b2..606e9a6 100644 --- a/Cakefile +++ b/Cakefile @@ -1,4 +1,4 @@ -sys = require 'sys' +util = require 'util' fs = require 'fs' path = require 'path' uglify = require 'uglify-js' @@ -29,7 +29,7 @@ replaceTokens = (js,tokens)-> task 'compress', 'compress javascript', -> invoke 'clean' - fs.mkdir(distPath,0755) + fs.mkdir(distPath,0o0755) compressed = minify(fs.readFileSync('src/jquery.maskedinput.js','utf8')) final=replaceTokens(compressed,plugin) fs.writeFileSync(path.join(distPath,'jquery.maskedinput.min.js'), final) diff --git a/spec/Focus.Spec.js b/spec/Focus.Spec.js index c59645f..3c0359c 100644 --- a/spec/Focus.Spec.js +++ b/spec/Focus.Spec.js @@ -62,6 +62,32 @@ feature("Leaving A Masked Input",function(){ }); }); +feature("Leaving A Masked Input With retainPartial",function(){ + scenario("All placeholders filled",function(){ + given("a mask with two placeholders",function(){ + input.mask("99", { retainPartial: true }); + }); + when("typing two characters and blurring",function(){ + input.mashKeys("12").blur(); + }); + then("value should be correct",function(){ + expect(input).toHaveValue("12"); + }); + }); + + scenario("Empty placeholders remaining",function(){ + given("a mask with two placeholders",function(){ + input.mask("99"); + }); + when("typing one character and blurring",function(){ + input.mashKeys("1").blur(); + }); + then("value should be empty",function(){ + expect(input).toHaveValue(""); + }); + }); +}); + feature("Optional marker",function(){ scenario("Placeholders not filled to marker",function(){ given("a mask with an optional marker",function(){ diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index af67604..cd7a2d1 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -206,8 +206,10 @@ } } if (!allow && lastMatch + 1 < partialPosition) { - input.val(""); - clearBuffer(0, len); + if (! settings.retainPartial) { + input.val(""); + clearBuffer(0, len); + } } else if (allow || lastMatch + 1 >= partialPosition) { writeBuffer(); if (!allow) input.val(input.val().substring(0, lastMatch + 1)); From e0f59b8ee67f23df98a2df7bf90614dba989aa13 Mon Sep 17 00:00:00 2001 From: Eduardo Arino de la Rubia Date: Fri, 16 Nov 2012 11:32:55 -0800 Subject: [PATCH 2/2] Retain dissapearing behavior on an empty field. --- src/jquery.maskedinput.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jquery.maskedinput.js b/src/jquery.maskedinput.js index cd7a2d1..545e693 100644 --- a/src/jquery.maskedinput.js +++ b/src/jquery.maskedinput.js @@ -206,7 +206,7 @@ } } if (!allow && lastMatch + 1 < partialPosition) { - if (! settings.retainPartial) { + if (lastMatch == 0 || ! settings.retainPartial) { input.val(""); clearBuffer(0, len); }