Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct time mask #39

Open
disshishkov opened this issue Jul 31, 2013 · 4 comments
Open

Correct time mask #39

disshishkov opened this issue Jul 31, 2013 · 4 comments

Comments

@disshishkov
Copy link

There is way to have correct time mask? 23:59
Default options is 29:59, that it allows to enter 15:00, but it also doesn't restrict 25:00

@emaiax
Copy link
Contributor

emaiax commented Feb 25, 2014

I'm also experiencing this issue. There's any patch to fix this?

@mrapaka
Copy link

mrapaka commented Feb 25, 2014

Hi,
I resolved this issue with the combination of mask and regular jquery keypress event.
If the first letter entered is '2' then I am changing the mask value to "23:59".
My code is
$("body").on("keyup", "input[alt='time']", function (event) {
if (event.keyCode != 9 && event.keyCode != 16 && (event.keyCode < 37 || event.keyCode > 40)) {
var value = $(this).val();
hours= value.split(':')[0];
if (hours.length == 1) {
if (parseInt(value) == 2) {
$(this).setMask("23:59");
} else {
$(this).setMask("29:59");
}
}
}
});

@disshishkov
Copy link
Author

Hi @emaiax I use a similar to @mrapaka "hack", but built-in mask for time will be great and it would not confuse many users.

$("input[alt='time']").setMask().keypress(function ()
    {
        var currentMask = $(this).data('mask').mask;
        var newMask = $(this).val().match(/^2.*/) ? "23:59" : "29:59";
        if (newMask != currentMask)
        {
            $(this).setMask(newMask);
        }
    });

@emaiax
Copy link
Contributor

emaiax commented Feb 25, 2014

@disshishkov I've used the same approch. Thanks a lot! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants