• Resolved wilfried1954

    (@wilfried1954)


    Hello,

    According to the documentation I can use my own js files. According to the documentation should be placed in /wp-content/plugins/calculated-fields-form/js/fields-public/

    There are however 2 problems:
    1. it does not work
    2. when the plugin is upgraded the file I placed there is gone

    For 1: I just made a testfile named test.js with following content:
    function half(number) {
    return number / 2;
    }

    And in the calculated field: ( function () {
    return half(100);
    } ) ()

    But there is no result shown.

    and for 2: it should not be deleted if upgrading the add-on.

    Please advise?

    Thank you, Wilfried

    • This topic was modified 6 years, 7 months ago by wilfried1954.
Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @wilfried1954,

    If you have ticked the checkbox: “Activate Javascript Cache” in the settings page of the plugin, you should untick it to allow the changes take place.

    If you don’t want lost the changes with the plugin’s updates, there are multiple alternatives.

    – Include the functions into the form’s structure, inserting “HTML Content” fields with a pair of <script>...</script> tags as their contents with the javascript functions.

    – Create a child theme, and move the code to this theme.

    Please, send me the URL to the webpage where form is inserted.

    Best regards.

    Thread Starter wilfried1954

    (@wilfried1954)

    Hello,

    Thank you for your fast answer.

    I’m not sure where to find the checkbox (I use free version).

    I tryed to put a HTML content into the form with following content:
    <script src=”/test.js”></script>

    Then I put the test.js in root folder.

    But now in preview the form is not displayed anymore.

    I do the test on a virtual machine to not break anything on production webpages.

    Can you advice some more? Eventually I can make a simple form on production page.

    Plugin Author codepeople

    (@codepeople)

    Hello @wilfried1954,

    The process is simpler:

    – First, create a new js file into the following directory: “/wp-content/plugins/calculated-fields-form/js/fields-public” (the file would be included into the code by default, you don’t need any other action)

    – Second, create the new function with a global scope:

    
    window['half'] = function (number) {
    return number / 2;
    };
    

    – Finally, to be sure the new file is loaded, go to the settings page of the plugin, through the menu option: “Settings/Calculated Fields Form”, untick the checkbox: “Activate Javascript Cache”, and press the “Update” button.

    and that’s all, you can use the new operation: half in the equations.
    Best regards.

    Thread Starter wilfried1954

    (@wilfried1954)

    Hello,

    Thank you, this works. It is simple if you know it ??

    But when the plugin is update then the file will be deleted. Is the only option to create a child plugin? Or is there another way, for example to put some of my own js files in another directory?

    rgds, Wilfried

    Plugin Author codepeople

    (@codepeople)

    Hello @wilfried1954,

    There are different alternatives:

    – Create a custom plugin to load your own scripts. In this case you can use the filter: “cpcff_pre_form”. For example, assuming the script to load is located directly into the root of your plugin, into the file: example.js

    
    add_filter('cpcff_pre_form', 'custom_plugin_pre_form');
    function custom_plugin_pre_form($param)
    {
    wp_enqueue_script( 'your_custom_script', get_template_directory_uri().'/example.js');
    return $param;
    }
    

    – Another alternative would be inserting the script tag as part of the form’s code, however, in this case you should check when the script file was loaded to evaluate the equations:

    Insert a “HTML Content” field and enter as its content:

    
    <script>
    fbuilderjQuery(document).one('showHideDepEvent', function(){
    var $ = fbuilderjQuery;
    $.getScript('//your-website.com/path-to-the-file/example.js', function(){
    $.fbuilder.fbuilder.calculator.defaultCalc('#cp_calculatedfieldsf_pform_1');
    });
    });
    </script>
    

    Best regards.

    Thread Starter wilfried1954

    (@wilfried1954)

    Thank you.
    Best regards, Wilfried

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘using my own js files’ is closed to new replies.