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..545e693 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 (lastMatch == 0 || ! settings.retainPartial) { + input.val(""); + clearBuffer(0, len); + } } else if (allow || lastMatch + 1 >= partialPosition) { writeBuffer(); if (!allow) input.val(input.val().substring(0, lastMatch + 1));