K
K
KTG2018-12-06 06:27:31
JavaScript
KTG, 2018-12-06 06:27:31

My jquery conflicts with other libraries, how to fix (Bitrix)?

In general, I want to add input masks in the form.reslut.new component template.
To do this, I created a js folder in the body of the template and threw jquery.maskedinput.min.js there. I
connect it to template.php in this way:

CJSCore::Init(array("jquery"));
 $APPLICATION->AddHeadString("<script src='".$this->__folder."/js/jquery.maskedinput.min.js'></script>", true);

I also add a mask handler there.
<script>
  $(function()
    {
      $('input[data-type="phone"]').mask("(999)999 99 99");
    });	
</script>

The console returns an error:
$(...).mask is not a function

Found out that this is due to a conflict with other connected libraries.
Actually with the same jquery.
Naryl that you need to write a conflict resolution string, and set an alias for your function. BUT:
If I write like this
$.noConfliсt(), one plugin falls off (jquery.lightboxcustom). He begins to swear at some of his functions, that it is not a function at all.
I write like this:
$.noConfliсt(true)- another plugin falls off (jquery.tabs).
Creating an alias doesn't help either.
var tmp = $.noConflict()

Where other libraries are used - I don't know, maybe in headers or footers of the main theme.
In general, is there any option for all libraries to work?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
O
ocatoll, 2018-12-06
@ocatoll

Maybe your script $('input[data-type="phone"]').mask("(999)999 99 99");
runs before jquery.maskedinput.min.js is included? Also check that jquery.maskedinput.min.js is included at all.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question