How to avoid conflicts with libraries on the same page

  • HospiceUK
    Asked on September 28, 2017 at 6:38 AM

    I need to embed JotForm into my webpages because I wish to do some clever javascript with the form elements.

    The CMS that the website is built in utilises JQUERY and this clashes with JotForm. Can you please change your libraries, or offer an alternative? Would this really be that much work?

    Sadly embedding JotForm stops the entire CMS from working.

    Another option would be to enable the insertion of a script element into your form builder...

    thanks


  • aubreybourke
    Replied on September 28, 2017 at 10:02 AM

    Yes it is possible to avoid conflicts with other JavaScript libraries on your page.

    The solution is to replace $ with jQuery

    Here is the official documentation

    http://learn.jquery.com/using-jquery-core/avoid-conflicts-other-libraries/



  • HospiceUK
    Replied on October 2, 2017 at 5:16 AM

    Firstly, thanks for responding.

    I am aware of the workarounds to change the JQuery reference, and this is of course possible if you are in control of the code.

    Most companies are using a CMS system and have no control of the backend.

    Just placing JotForm code into a page in the CMS my organisation uses kills the backend entirely.

    Can JotForm not rebuild the library, or offer a workaround like JQuery do?


  • BJoanna
    Replied on October 2, 2017 at 9:33 AM

    Which embed code did you use?

    Which Form Embed Code Should I Use?

    If you used the script embed code, there is a possibility that there is a script conflict between your website scripts and a form script. 

    To avoid the script conflicts I would suggest you to embed your form with the iFrame code:

    Getting the Form iFrame Code

  • HospiceUK
    Replied on October 2, 2017 at 9:52 AM

    Thanks once again for a response. 

    We cannot use an iframe unless JotForm allows scripts to be added to their form designer.

    Andrew

  • BJoanna
    Replied on October 2, 2017 at 11:00 AM

    Unfortunately, it is not possible to add scripts to the Form Builder.

    The only way to add script to your form is use your form full source code, embed it to your website and add the scripts there. 

    How to get the Full Source Code of your Form

  • HospiceUK
    Replied on October 2, 2017 at 11:04 AM

    Yes thanks for your response. But, can we look at resolving this? I've read many forum posts and responses on this subject, and tried many different approaches to solving this. How long would it take to change your library so that it doesn't use $? perhaps use $jf? Or, perhaps offer a work-around like jQuery does? Thanks.

  • BJoanna
    Replied on October 2, 2017 at 11:44 AM

    Please try to add noconflict code before the form source code:

    <script type="text/javascript">  $.noConflict();</script>

    If that does not work, try with:

    <script type="text/javascript">  jQuery.noConflict();</script>

    If noconflict codes dose not help you, please provide us your webpage URL. 

  • HospiceUK
    Replied on October 2, 2017 at 11:54 AM

    Hi, I have tried the noConflict() workaround. As recommended in all your responses to this problem. This will work for some people - but not all. I cannot provide a URL because JotForm crashes the CMS system so much so that I cannot publish a page. I am an experienced developer, and have no problems implementing JotForm on my own built pages, and have used the noConflict to bypass conflicts. But, for some systems and some situations a workaround isn't going to work - like mine. Please answer my question about how long it would take for JotForm to publish an alternative library changing the reference $ to something more unique to JotForm. Imagine the number of reduced support calls, and the more people using JotForm!

  • Elton Support Team Lead
    Replied on October 2, 2017 at 12:40 PM

    Unfortunately, we do not have yet plans on moving our form source code with jQuery since it was entirely written with the prototype. When our team wrote the first version of JotForm, jQuery was not released. We know that jQuery is very popular but for the kind of things we are doing, the prototype was the only option back then.

    You can actually remove the prototype script that is in the form source code. The form should still work and submittable but without working field validations, calculations and conditions. However, you can write your own jQuery based scripts for the validation, calculation and etc.

    Thanks

  • HospiceUK
    Replied on October 4, 2017 at 4:49 AM

    Sadly I need the encryption element, which doesn't seem to work when removing the prototype script. Thanks for your thoughts. I really thought there may be a way of getting JotForm working with the CMS our company uses - SiteFinity. It's a shame you don't offer the ability to add a bit of JavaScript to your forms - this would allow so much more flexibility within JotForm.

    I actually managed to get the CMS working again by reclaiming $ for JQuery after inserting the JotForm code, but this crashes the encryption. Such a shame :(

    thanks,

    Andrew

  • HospiceUK
    Replied on October 4, 2017 at 6:23 AM

    I have managed to create a workaround to resolve the issue. Yay. I have added some javascript that checks to see if the page is in edit mode, and if so switches $ back for jQuery use.

  • candy
    Replied on October 4, 2017 at 6:26 AM

    Dear Andrew,

    On behalf of my colleagues, we are glad that you have managed to create another workaround to resolve your issue.

    Besides, with your understanding, we can not allow injecting javascript directly to forms due to security reasons.

    Thank you for contacting us.