jquery masked input plugin to not clear field when errored

47,594

Solution 1

It looks like I should just make the whole mask optional:

mask('?999-999-9999')

That way the control thinks what the user has is "valid" and I can continue. Even though it isn't really the optional part of the mask.

Solution 2

Set autoclear option to false.

$(control).mask('999-999-9999', {autoclear: false});

Solution 3

You should delete statement input.val(""); in checkVal() function for a proper solution.

If you're using minified version, you should search and delete statement:

if(!a&&c+1<i)f.val(""),t(0,k);else
Share:
47,594
McKay
Author by

McKay

I'm a geek. I've been doing a lot of Node and Typescript recently, but Python is still deeply embedded in my life. C# / .NET stack (XNA, WCF, WPF...) is still something I look fondly upon. I've also done a lot with Databases (all the way down to RDBMS theory), algorithms, and scalability I'm #SOreadytohelp

Updated on January 29, 2020

Comments

  • McKay
    McKay over 4 years

    I'm looking at the http://digitalbush.com/projects/masked-input-plugin/

    I'm calling it like this:

    $(control).mask('999-999-9999');
    

    And I don't want it to throw away the users input if something is wrong, e.g. they haven't finished

    [407-555-____]
    

    If you leave the field after having typed this much, it clears it. I'd like to leave it so they can finish later.

    I'm new to jQuery, and I've looked through his source, but I can't find any way to do that, nor can I find any way to edit it to accomplish what I want, because the code is arcane to my eyes.