• Resolved borlee123

    (@borlee123)


    Hello. There is a slider, how to return to the calculated field, the first step of the slider, the initial number is 5050 plus 675, the next sum of the previous + 675? Help, please.

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

    (@codepeople2)

    Hello @borlee123

    Thank you so much for using our plugin! If you have a slider field named fieldname123, for example, and you want to modify its value using code. For instance, you might want to set its value to 5725.

    Insert a calculated field as an auxiliary. Configure it as hidden and exclude it from the submission by checking the corresponding boxes in its settings. Finally, enter the equation:

    getField(fieldname123|n).setVal(5725);

    If you want to use the minimum slider value and add another field’s value (fieldname456) to it, the equation would be:

    getField(fieldname123|n).setVal(SUM(getField(fieldname123|n).min, fieldname456))

    Note the use of the |n modifier with the field name fieldname123|n. The plugin replaces the field names with their values in the equation before evaluating it. The |n modifier indicates that you are referring to the field name directly rather than its value.

    Best regards.

    Thread Starter borlee123

    (@borlee123)

    Maybe I didn’t explain it correctly. I need to increase the value of the calculated field, at each step of the slider, by the previous value of the calculated field + a certain number.

    Thread Starter borlee123

    (@borlee123)


    I can write it using if , but I will need to describe about 1000 values.
    When there weren’t so many meanings, I wrote like this

    IF(AND(fieldname8>=0, fieldname8<=10),5985, IF(AND(fieldname8>=11, fieldname8<=21),11555, IF(AND(fieldname8>=21, fieldname8<=31),16880, IF(AND(fieldname8>=31, fieldname8<=41),22205, IF(AND(fieldname8>=41, fieldname8<=51),27530, IF(AND(fieldname8>=51, fieldname8<=62),34175, IF(AND(fieldname8>=62, fieldname8<=71),39500, IF(AND(fieldname8>=71, fieldname8<=81),44825, IF(AND(fieldname8>=81, fieldname8<=91),50150, IF(AND(fieldname8>=91, fieldname8<=101),55475 , IF(AND(fieldname8>=101, fieldname8<=111),62780, IF(AND(fieldname8>=111, fieldname8<=121),68105, IF(AND(fieldname8>=121, fieldname8<=131),73430, IF(AND(fieldname8>=131, fieldname8<=141),78755, IF(AND(fieldname8>=141, fieldname8<=151),84080,
    )))))))))))))));

    Thread Starter borlee123

    (@borlee123)

    fieldname8 is a slider and for certain values ​​of fieldname8 I changed the value of the calculated field

    Plugin Author CodePeople2

    (@codepeople2)

    Hello @borlee123

    Your solution is correct. However, I prefer to use the function structure for the equation instead of nesting multiple “IF” operations, because it is more readable and easier to maintain in the future.


    (function(){
    let f8 = fieldname8;
    if(f8 <= 10) return 5985;
    if(f8 <= 21) return 11555;
    if(f8 <= 31) return 16880;
    if(f8 <= 41) return 22205;
    if(f8 <= 51) return 27530;
    if(f8 <= 61) return 34175;
    if(f8 <= 71) return 39500;
    if(f8 <= 81) return 44825;
    if(f8 <= 91) return 50150;
    if(f8 <= 101) return 55475;
    if(f8 <= 111) return 62780;
    if(f8 <= 121) return 68105;
    if(f8 <= 131) return 73430;
    if(f8 <= 141) return 78755;
    if(f8 <= 151) return 84080;
    })()

    Keep in mind that your equation needs multiple “if” conditional statements because there is no straightforward algorithm for your request.

    For example, if your slider step is 10, and every step represents an increment of 5325 in the calculated field’s equation, and the base value is 660 (note these values are hypothetical, I’m using them based on your code values). The equation could be implemented as follows:

    660+MAX(1,CEIL(fieldname8/10))*5325

    The previous code is an hypothetical example for an equation that represents a specific process for value calculation.

    Best regards.

    Thread Starter borlee123

    (@borlee123)

    hi, i’m stuck. i used your previous advice, but i can understand why it works like that.

    IF(AND(fieldname197>=0,fieldname197<=3),6115,
    IF(AND(fieldname197>=4,fieldname197<=10),6115+MAX(1,CEIL(fieldname197))*878),....

    I thought that this code would increase 6115 by 878, each step of the slider after 4, but on the 4th step of the slider the number 878 is multiplied by 4, the number 9627 is displayed and on the 5th step of the slider it already works as it should. If you can, tell me the solution to the problem

    Plugin Author CodePeople2

    (@codepeople2)

    Hello @borlee123

    Could you please provide the URL to the page containing the form to check the field’s settings? I don’t understand your explanation.

    However, if you want to increase the base number 6115 by 878 for each step over 4 in fieldname197, the equation would be as simple as:

    6115+878*(MAX(fieldname197-4,0))

    And that’s all. You don’t need to use conditional statements or any other complex operation. It is a simple mathematical expression.

    Best regards.

    Thread Starter borlee123

    (@borlee123)

    Thank you, your advice helped.

    Plugin Author CodePeople2

    (@codepeople2)

    Hello @borlee123

    If you have been satisfied with both the plugin and our support, we would be immensely grateful if you could leave us a review on the plugin ( https://ww.wp.xz.cn/support/plugin/calculated-fields-form/reviews/ ). Your feedback will help us reach more users. 

    Best regards. 

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

The topic ‘Calculated field’ is closed to new replies.