• Resolved allansjackson

    (@allansjackson)


    Sorry to trouble you again so soon. I have finally got my form built with your help but I have struck a problem with the amount of text a calculated field can display.

    What I wanted to achieve is a calculator with 7 self-assessment questions that returns a short assessment based on a score. I have got all this to work but then discovered that the calculated field won’t display more than the first few characters of the assessment even though I have figured out how to make the field bigger using this code:

    .cff-calculated-field input{font-size:1.5em !important;
      width: 600px !important;
      height: 150px !important;
    }

    Is there another approach I can use. The assessment will only be a sentence or two long.

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

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

    (@codepeople)

    Hello @allansjackson

    Yes of course, that’s happening because the calculated fields include input tags, and the input tags accept only one line of text. So, the alternative would be to use the calculated field as auxiliary, but display the result in another field.

    Please, follow the steps below:

    1. Insert a “HTML Content” field in the form, and enter as its content a DIV tag with an unique id (tag where will be displayed the equation’s result):

    <div id="result_here"></div>

    2. Now, select the calculated field, and tick the checkbox: “Hide Field From Public Page” in its settings (as the calculated field will be used as auxiliary, it should not be visible in the form).

    3. Finally, edit the equation associated to the calculated field as follows:

    
    (function () {
    	var sum = (fieldname1 + fieldname8 + fieldname5 + fieldname6 + fieldname7 + fieldname10 + fieldname9),
    		result = '';
    	if (sum < 8)
    		result += 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum interdum a felis vel vehicula 1-7';
    	else if (sum < 15)
    		result += 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum interdum a felis vel vehicula 8-14';
    	else
    		result += 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum interdum a felis vel vehicula 15-21';
    
    	jQuery('#result_here').html(result);
    	return result;
    })()
    

    and that’s all.
    Best regards.

    Thread Starter allansjackson

    (@allansjackson)

    Thanks very much. That worked perfectly.

    Thread Starter allansjackson

    (@allansjackson)

    Hi There
    I’m sorry to trouble you again but the client has now given me the data for the form and I have edited the equation. The calculating field is working if I unhide it but the result does not appear in the the html field.

    The equation is:

    (function () {
            var sum = (fieldname1 + fieldname8 + fieldname5 + fieldname6 + fieldname7 + fieldname10 + fieldname9),
                    result = '';
            if (sum < 8)
                    result +='You probably do not have immediate issues but regular health checks may prevent any issues occurring.';
            else if (sum < 18)
                    result +='It is worth giving us a call to see if minor tweaks in your systems can improve your score.';
            else
                    result +='You definitely should be giving us a call.';
    
     jQuery('#result_here').html(result);
            return result;
    })()

    and the code in the html field is:

    
    <h3>Our opinion is</h3>
    <div id="result_here"></div>

    I can’t see where I’ve gone wrong. The code you provided worked fine but an error has crept in.

    Plugin Author codepeople

    (@codepeople)

    Hello @allansjackson

    The equation’s structure and the HTML piece of code in your entry are correct. Please, send me the URL to the page where the form is inserted for checking the code in action.

    Best regards.

    Thread Starter allansjackson

    (@allansjackson)

    Plugin Author codepeople

    (@codepeople)

    Hello @allansjackson

    The error is not the equation, the error is in the dependency. You have defined the fieldname11 as dependent, and the dependency was defined in the calculated field. However, you are comparing with a number (If value is greater than 1), but the equation is returning a text. In this case the equation should be edited as follows to return a number too:

    
    (function () {
            var sum = (fieldname1 + fieldname8 + fieldname5 + fieldname6 + fieldname7 + fieldname10 + fieldname9),
                    result = '';
            if (sum < 8)
                    result +='You probably do not have immediate issues but regular health checks may prevent any issues occurring.';
            else if (sum < 18)
                    result +='It is worth giving us a call to see if minor tweaks in your systems can improve your score.';
            else
                    result +='You definitely should be giving us a call.';
    
     jQuery('#result_here').html(result);
            return sum;
    })()
    

    Best regards.

    Thread Starter allansjackson

    (@allansjackson)

    Great. That sorts that out. Thanks very much.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Size of Caluculated Field’ is closed to new replies.