when I upgrade my jquery.inputmask plugin from 3.3.1 to 3.3.4, I noticed that datetime format for mask is changed.
// in version 3.3.1
$("#textbox").inputmask("y-m-d");
$("#textbox").inputmask("h:s");
// in version 3.3.4
$("#textbox").inputmask("yyyy-mm-dd");
$("#textbox").inputmask("hh:mm");
In v3.3.4, letter "m" is used for both "month" and "minute", some mask definitions are likely to cause conficts, for example
$("#textbox").inputmask("yyyy-mm-dd hh:mm"); // ERROR! can't input anything into textbox
$("#textbox").inputmask("mm/dd/yyyy hh:mm xm"); // but this works fine
This problem only happens in jquery.inputmask 3.3.4
Is it a bug? How can I make the mask "year-month-day hour:minute" work in my page ?
After a bit of digging into the source code, it looks like you can use Inputmask.extendAliases to correct the bug by adding a custom alias for your specific use case:
Inputmask.extendAliases({
"yyyy-mm-dd hh:mm": {
mask: "y-1-2 h:s",
placeholder: "yyyy-mm-dd hh:mm",
alias: "datetime",
separator: "-"
}
})
$("#textbox").inputmask("yyyy-mm-dd hh:mm")
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://rawgit.com/RobinHerbots/Inputmask/3.x/dist/jquery.inputmask.bundle.js"></script>
<input id="textbox" type="text">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With