Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need to have date mask depending on the culture in jquery

MVC pages with culture depending on the user. In Search option (search can be done by DueDate), I need to have a mask on that DueDate text box. Mask must be dependant on the user's culture. In both js and cshtml have an error saying: mask.split is not a function. Changed my jquery.maskedinput-1.2.3.js from make.split to make.toString().split and the error is gone, but must looks like this: [object Object] or has some 01 numbers. Any idea? Code in cshtml looks like this:

   <script type="text/javascript">
    $(function () {
        var maskFormat = @Html.CurrentDateMask();
        $(".DateBox").mask(maskFormat);
    });
   </script>
like image 846
agmawe Avatar asked Dec 19 '12 12:12

agmawe


1 Answers

you could have maskFormat as a global variable (put it in the window object) and then refer it to window.maskFormat inside your JS file:

cshtml file:

(function () {
    window.maskFormat = "@Html.CurrentDateMask();";
})();

and in your Javascript file:

$(function(){
    $(".DateBox").mask(window.maskFormat);
});

but be careful so you don´t add to many global variables or with a name thats easy to overwrite

like image 99
voigtan Avatar answered Oct 20 '22 06:10

voigtan