• Resolved uponity

    (@uponity)


    i just try to create a global variable with a shortcode.
    But it’s not working.

    Create ist like in yout FAQ:

    Yes, it’s possible to define global variables in javascript through the shortcode of the plugin. For example, in the following shortcode [CP_CALCULATED_FIELDS id=”1″ myvar=”4″], the id=”1″ identifies the form to be loaded, and myvar=”4″ definess the global variable myvar with value 4, that you can use in the equations or the queries associated to the “DS” fields: <%myvar%>.

    Ex: If your form includes the number field: “fieldname1”, and a calculated field. A possible equation would be fieldname1*myvar

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Author codepeople

    (@codepeople)

    Hello @uponity

    Thank you very much for using our plugin.

    My apologies for the confusion. We are editing the FAQ entries because we modified the implementation of global variables to avoid plugin conflicts.

    In previous plugin versions, the shortcode directly creates the global variables, but this has a problem. If another plugin uses a javascript variable with the same name, the global variable will provoke a conflict. The same would happen with global browser variables like window.

    With recent plugin versions, the shortcode generates a cff_var object, where the shortcode variables are cff_var properties.

    So, if you insert the shortcode:

    [CP_CALCULATED_FIELDS id="1" myvar="4"]

    You can use it as follows:

    
    fieldname1*cff_var['myvar']
    
    or
    
    fieldname1*cff_var.myvar

    Best regards.

    Thread Starter uponity

    (@uponity)

    Great! Thank you.
    For equations it works.

    But how can i use the Value to prefill a normal field?
    If i try to insert <%cff_var.myvar%> as predefined value i don’t get the Value.

    Regards,

    Plugin Author codepeople

    (@codepeople)

    Hello @uponity

    In the current plugin version, you cannot use variables as fields predefined values directly, but you can assign them at runtime. For example, assuming you have the myvar variable:

    [CP_CALCULATED_FIELDS id="1" myvar="4"]

    And you want to use it as the default value of the fieldname123 field.

    Insert an “HTML Content” field in the form and enter the following piece of code as its content:

    
    <script>
    fbuilderjQuery(document).on('formReady', function(){
        getField('fieldname123').setVal(cff_var['myvar']);
    });
    </script>

    Best regards.

    Thread Starter uponity

    (@uponity)

    Great! Thank you very much!
    Works perfectly

    Plugin Author codepeople

    (@codepeople)

    Hello @uponity

    We are working in a notation that allows to assign Javascript variables as default fields values without ambiguity with plain values.

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.