0
Hey, how you doing? I’m with a little problem that has already consumed me a lot of time, I’m trying to put a mask for time in an input field, the code is already ok and running the problem is when I import the js library into the head of my header.php, because it uga the rest of my entire site, tried in some ways to import but nothing at the moment resolves, tried in the following ways:
var mask = function (val) {
val = val.split(":");
return (parseInt(val[0]) > 19)? "HZ:M0" : "H0:M0";
}
pattern = {
onKeyPress: function(val, e, field, options) {
field.mask(mask.apply({}, arguments), options);
},
translation: {
'H': { pattern: /[0-2]/, optional: false },
'Z': { pattern: /[0-3]/, optional: false },
'M': { pattern: /[0-5]/, optional: false }
},
placeholder: 'hh:mm'
};
var $a = jQuery.noConflict()
$a(document).ready(function () {
$a("#QuantidadeHoras").mask(mask, pattern);
});
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js');
wp_enqueue_script( 'jquery' );
wp_deregister_script( 'jquery' );
wp_register_script( 'jquery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.min.js');
wp_enqueue_script( 'jquery' );
Well I added to the header as usual, I tried to include in the footer but the bug buging some parts of the site continues: I added this way: <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.min.js"></script>
– Fernando
Including in the footer in this way nothing happens: wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', 'https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js'); wp_enqueu_script( 'jquery' ); wp_deregister_script( 'jquery' script); wp_register_script( 'jquery', 'https://cdnjs.cloudflare.com/ajax/libs/jquery.mask/1.14.0/jquery.mask.min.js'); wp_enqueue_script( 'jquery' );
– Fernando
then, for the little knowledge I have, including in wordpress, the problem that when you leave the other parts is because it is giving jQuery conflict, you can inspect the source code of the page and see that it is loading more than one version. I found a function in the gringo stack, see if it solves:
– Felipe Goncalves
Function starter_scripts() { wp_deregister_script( 'jquery' ); wp_register_script( 'jquery', includes_url( '/js/jquery/jquery.js' ), false, NULL, true ); wp_enqueue_script( 'jquery' ); &#wp_enqueue_style( 'Starter-style', 'stygetlesheet_uri() ); wp_enqueue_script( 'includes', get_template_directory_uri() . '/js/min/includes.min.js', ', ', true ); } add_action( 'wp_enqueue_scripts', 'starter_scripts' );
– Felipe Goncalves