• Resolved mate2001

    (@mate2001)


    Hello,
    I have the following problem. I want to display the result of a calculation in a number field.

    If I set the field name under Predefined Value (fieldname1), it does not work. Presumably because it is the result of a calculation. So I tried this: getField(2).setVal(fieldname1|r);. This works perfectly. However, the user cannot overwrite this number in the frontend.

    Example: The result 5 is automatically entered in the number field. In the frontend, however, the user wants to change this number to 7. This is not possible. It always jumps back to 5, so it cannot be overwritten. Basically, the number field is then useless for me. I could display the result straight away.

    So, how can I display the value of a calculation in the Predefined Value area AND make the value overwritable in the frontend?

    Thank you for your help.

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

    (@codepeople)

    Hello @mate2001

    Thank you very much for using our plugin.

    In short, you have an equation, for example, fieldname123+fieldname456, and you want to assign its result to another field in the form, the number field fieldname1, but you want to do it only the first time when the fieldname1 field is empty.

    In this hypothetical case, you can implement the equation in the calculated field as follows:


    (function(){
    let result = fieldname123+fieldname456;
    let f = getField(fieldname1|n);

    if(f.val(true, true) == '') f.setVal(result);

    return result;
    })()

    Best regards.

    Thread Starter mate2001

    (@mate2001)

    You can’t imagine how happy I am. Great, that works. Thank you very much!

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