• Resolved fooey

    (@fooey)


    I am trying to display a text message that will appear based on the value returned by a calculated field. Is that possible with the free version or is the paid version required? For example, I have a calculated field. If the results or value of the field returns lower than 500, I want a message of text to show but only if it’s under 500. Can you assist?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author CodePeople2

    (@codepeople2)

    Hello @fooey

    That’s possible with the free plugin distribution, and the solution is very simple.

    I’ll try to describe the process with a hypothetical example.

    Assuming you have a calculated field (I’ll call it fieldname1) whose equation is fieldname2+fieldname3, however, if the sum is lower than 500, you can display the text “the value is lower than expected”

    The simplest solution would be to include a conditional operation in the equation:

    IF(fieldname2+fieldname3<500, 'the value is lower than expected', fieldname2+fieldname3)

    Or if you prefer to implement the equation by using the function structure and the “if” conditional statement:

    (function(){
    let value = fieldname2+fieldname3;
    if(value<500) return 'the value is lower than expected';
    return value;
    })()

    If the text is longer than the input box of the calculated field, you can use it as an auxiliary field, only for calculation, but display the result in another field that doesn’t use an input box.

    In this case, you can configure the calculated field as hidden (remember it is use as an auxiliary for calculations) by ticking a checkbox in its settings, and insert an “HTML Content” field in the form and enter a DIV tag in its content (or any other HTML tag) with the data-cff-field attribute indicating the name of the field whose value you want to display in the tag. In this example, the data-cff-field contains the calculated field’s name:

    <div data-cff-field="fieldname1"></div>

    Another alternative is to use the SHOWFIELD and HIDEFIELD operations included in the “Managing Fields Operations” module (https://cff.dwbooster.com/documentation#managing-fields-module)

    In this case, you can insert an “HTML Content” field in the form (I will call it fieldname4) with the text directly in its content:

    the value is lower than expected

    And then, you can edit the equation in the calculated field as follows:

    (function(){
    let value = fieldname2+fieldname3;

    HIDEFIELD(fieldname4|n);
    if(value<500) SHOWFIELD(fieldname4|n);

    return value;
    })()

    Note that the fieldname4 in the equation includes the |n suffix or modifier. The plugin replaces the field names in the equations by their corresponding values before evaluating them. The |n modifier tells the plugin you are referring directly to the field’s name instead of its value.

    Learn more about the different modifiers by reading the text in the yellow frame, visiting the following link to the plugin documentation:

    https://cff.dwbooster.com/documentation#modifiers

    Best regards.

    Thread Starter fooey

    (@fooey)

    Here is the url with the form https://tinyurl.com/5n7kky9t

    I tried adding the function to the existing functions in the calculated field, and it just filled the calculated field box with the text I wanted to add. We still need to see the number displayed (results of the calculation), the text would be like a description or possibly another field that would display conditionally based on whether that number is at or below 500. Here is the current function for the calculated field:

    (function(){
    if(fieldname3 == 1) return PREC(fieldname2/15650*100, 2); if(fieldname3 == 2) return PREC(fieldname2/21150*100,2);
    if(fieldname3 == 3) return PREC(fieldname2/26650*100,2); if(fieldname3 == 4) return PREC(fieldname2/32150*100,2);
    if(fieldname3 == 5) return PREC(fieldname2/37650*100,2); if(fieldname3 == 6) return PREC(fieldname2/43150*100,2);
    if(fieldname3 == 7) return PREC(fieldname2/48650*100,2); if(fieldname3 == 8) return PREC(fieldname2/54150*100,2);
    })();

    I also tried adding a new html field and used SHOWFIELD HIDEFIELD but it always showed the html field no matter the value of the calculated field. What am I missing? I appreciate the guidance.

    Plugin Author CodePeople2

    (@codepeople2)

    Hello @fooey

    Ok, please follow the steps below:

    1. Insert an HTML Content field in the form and enter the text you prefer in its content.

    2. In the “Advanced Settings” tab of the “HTML Content” field, tick the checkbox to hide the field to hide it by default.

      For the next step, I will assume the HTML Content field’s name is fieldname123 (please use the correct field’s name in your form).

      3. Finally, edit your current equation as follows:


      (function(){
      let divider = {1:15650, 2:21150, 3:26650, 4:32150, 5:37650, 6:43150, 7:48650, 8:54150};
      let result = fieldname2/divider[fieldname3]*100;

      HIDEFIELD(fieldname123|n);
      if(result < 500) SHOWFIELD(fieldname123|n);

      return PREC(result,2);
      })();

      Please note that I edited your equation for optimization purposes. I reduced the number of “if” conditional statements and the volume of code.

      Thread Starter fooey

      (@fooey)

      That’s it! Thank you so much for the extremely fast replies and solid resolution.

    Viewing 4 replies - 1 through 4 (of 4 total)

    You must be logged in to reply to this topic.