Support » Plugin: Calculated Fields Form » Help with final output result

  • Resolved iamdavidkennedy

    (@iamdavidkennedy)


    Hey,

    I’ve set up a form using CFF that has to take a series of scores and output them as a final bit of advice for runners.

    The format is essentially

    Title
    (five questions numberically valued 1 – 5)

    This repeats five times before going to the final page where all 5 numerical scores are displayed and then the form user takes the highest score as their result.

    However i need to find a way to do two things, firstly, I want that end result to display below showing the Title instead of the number for the outcome

    And then alongside that, I need to know how to make sure that if for example, 2 of the scores match, it takes the first of the two, in list order, as the one to display (basically heirachy from 1 – 5 so if scores matched on question set 2 and 4, it would pick the result from set 2 as the answer)

    I hope that makes sense if not please let me know and I can get you any other information you need

    The page I need help with: [log in to see the link]

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

    (@codepeople)

    Hello @iamdavidkennedy

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

    Assuming the 5 calculated fields are: fieldname1, fieldname2, fieldname3, fieldname4 and fieldname5. The equation in the final calculated field would be similar to:

    
    (function(){
        var titles = [getField(fieldname1|n).title, getField(fieldname2|n).title, getField(fieldname3|n).title, getField(fieldname4|n).title, getField(fieldname5|n).title],
            values = [fieldname1,fieldname2,fieldname3,fieldname4,fieldname5],
            tmp = 10000,
            result;
        for(var i in values)
        {
            if(values[i]<tmp)
            {
                result = titles[i]+': '+values[i];
                tmp = values[i];
            }
        }
        return result;
    })()
    

    Best regards.

    Thread Starter iamdavidkennedy

    (@iamdavidkennedy)

    Hey thanks so much for getting back to me so quickly @codepeople

    Unfortunately I can’t seem to get that to work, I’ve changed it to:

    <script>
    (function(){
        var titles = [getField(fieldname47|n).title, getField(fieldname49|n).title, getField(fieldname50|n).title, getField(fieldname51|n).title, getField(fieldname52|n).title],
            values = [fieldname47,fieldname49,fieldname50,fieldname51,fieldname52],
            tmp = 10000,
            result;
        for(var i in values)
        {
            if(values[i]<tmp)
            {
                result = titles[i]+': '+values[i];
                tmp = values[i];
            }
        }
        return result;
    })()
    </script>

    Really appreciate any help, basically once you get through to page six of the form at the link, I need the name from the “Your total scores are shown below” section to display in the “Based on your above scores we recommend you focus on:” section – so it should say whichever the highest scoring value is from above e.g; ‘Stability’

    Plugin Author codepeople

    (@codepeople)

    Hello @iamdavidkennedy

    I sent you the code of an equation, and the equations must be entered through the “Set Equation” attribute of calculated fields. That was not what you did in your form.

    Best regards.

    Thread Starter iamdavidkennedy

    (@iamdavidkennedy)

    Hey again @codepeople

    Gotcha thanks, I’ve put it in there and it’s now pulling in a result as

    ‘Stamina:1’

    I need it to be sorting the items by their max value, so the one with the highest value (5 in this case) should be the one it displays in that final field

    max(fieldname10,fieldname21,fieldname30,fieldname39,fieldname44)

    That’s how I was previously pulling that result in but as the number, how can I apply that same rule combined with the code you gave me?

    Thanks again!

    Plugin Author codepeople

    (@codepeople)

    Hello @iamdavidkennedy

    The code provided previously returns the min value, if you want the max value the process would be similar, but changing the direction of comparison and the initial value of the tmp variable:

    
    (function(){
        var titles = [getField(fieldname47|n).title, getField(fieldname49|n).title, getField(fieldname50|n).title, getField(fieldname51|n).title, getField(fieldname52|n).title],
            values = [fieldname47,fieldname49,fieldname50,fieldname51,fieldname52],
            tmp = -10000,
            result;
        for(var i in values)
        {
            if(tmp<values[i])
            {
                result = titles[i]+': '+values[i];
                tmp = values[i];
            }
        }
        return result;
    })()
    

    Best regards.

    Thread Starter iamdavidkennedy

    (@iamdavidkennedy)

    @codepeople amazing that’s working absolutely perfectly for me, thank you for all your help and an amazing support service, above and beyond 🙂

    Take care and stay safe

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Help with final output result’ is closed to new replies.