Formatting date field with jQuery Masked Input [closed]

2

Dear, I have searched and tested in a number of ways how to format a date field in jQuery but it is not working.

I have already imported the jQuery Masked Input into the JSP:

src='<%=renderResponse.encodeURL(renderRequest.getContextPath()
                        + "/js/jquery/jquery.maskedinput-1.2.2.js")%>'>

My date field:

<td align="right">Data Inicial:</td>
<td class="form_text"><input type="text" name="dataInicial" id="dataInicial">

And the jQuery function like this:

jQuery(function($){
   $("#dataInicial").mask("99/99/9999");
});

Can anyone tell me if I'm eating the ball somewhere?

    
asked by anonymous 14.01.2015 / 12:23

2 answers

5

What happens is that you do not get the jQuery object in the $ variable because the value of it is coming as a parameter by the function and not directly from the window object as it normally does. Using the jQuery function directly solves the problem:

jQuery("#dataInicial").mask("99/99/9999");

Or, pass jQuery as a parameter to the function:

(function($) {
    $("#dataInicial").mask("99/99/9999");
)(jQuery);
    
14.01.2015 / 12:53
1

I'm using mask in the contact of my platform here . I tested it by adding your input and with the script below, I ran it regularly on localhost.

I tried to put the example in JSFIDDLE, but I had problems with external references.

$(document).ready(function () {
    $("#dataInicial").mask("99/99/9999");
});

If it does not work, check the import order of the script and jQuery, along with Chrome view the imported elements. To do this, follow the instructions below: Press F12 > Click Network > Refresh Page

Anything that is not found will turn red.

In addition you can check the lack of script integrity via Console. To do this, press F12 and then ESC.

    
14.01.2015 / 12:30