• Resolved kapdev

    (@kapdev)


    I need help resolving an issue with wrapping text in a calculated field. I have tried using the suggestion given in another thread mentioning wrapping text by using a Content HTML field, but have been unsuccessful. My calculation is as follows: If age less than x, return y and so forth. The function works properly but the one line limitation doesn’t allow the entire sentences to be shown. Here is the function:

    (function(){
    if(fieldname23 < 2) return "First sentence here";
    if(fieldname23 < 8) return "Second sentence here, and an explanation to go along with it, as well as a suggestion to possible solutions to the problem.";
    if(fieldname23 < 11) return "Third sentence here";
    if(fieldname23 >= 12) return "Fourth sentence here";
    })()

    The issue is with the Second sentence as it is long.

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

    (@codepeople)

    Hello @kapdev

    Please, follow the steps below:

    1. Insert an “HTML Content” field in the form, and enter the following piece of code as its content:

    <div class="result-here"></div>

    2. Now, edit the equation as below:

    (function(){
    var result = '';
    
    if(fieldname23 < 2) result = "First sentence here";
    else if(fieldname23 < 8) result = "Second sentence here, and an explanation to go along   with it, as well as a suggestion to possible solutions to the problem.";
    else if(fieldname23 < 11) result = "Third sentence here";
    else result = "Fourth sentence here";
    
    jQuery('.result-here').html(result);
    return result;
    })()

    3. Finally, as the calculated field is used as an auxiliary, tick the “Hide Field From Public Page” checkbox in its settings.

    Best regards.

    Thread Starter kapdev

    (@kapdev)

    Thank you for your quick response. Unfortunately this did not solve my problem. In case this is relevant, the field which is a calculated field (fieldname37) is referenced from a dropdown menu. If a person selects C, fieldname 37 is shown. As of now, with the solution that was suggested, I click on C on the dropdown menu and nothing happens.

    Plugin Author codepeople

    (@codepeople)

    Hello @kapdev

    Please, send me the URL to your form to check your code in action.

    Best regards.

    Thread Starter kapdev

    (@kapdev)

    Nauseas y Vomitos
    On.setron Denk

    That is where I replaced the code. Other selections have the same issue, but I tried it only there

    • This reply was modified 3 years, 5 months ago by kapdev.
    • This reply was modified 3 years, 5 months ago by kapdev.
    Plugin Author codepeople

    (@codepeople)

    Hello @kapdev

    You have copied and pasted the equation code encoded as HTML. Please, type the equation directly into the “Set equation” attribute.

    Best regards.

    Thread Starter kapdev

    (@kapdev)

    I didn’t paste de equation into HTML.

    I copied this into HTML:

    <div class=”result-here”></div>

    And this under Set Equation in Calculated Field, right below the checkbox to hide from public view:

    (function(){
    var result = '';
    
    if(fieldname23 < 2) result = "First sentence here";
    else if(fieldname23 < 8) result = "Second sentence here, and an explanation to go along   with it, as well as a suggestion to possible solutions to the problem.";
    else if(fieldname23 < 11) result = "Third sentence here";
    else result = "Fourth sentence here";
    
    jQuery('.result-here').html(result);
    return result;
    })()
    Thread Starter kapdev

    (@kapdev)

    the link was wrong. Here is the correct one

    Plugin Author codepeople

    (@codepeople)

    Hello @kapdev

    I’ve checked your form and no, you don’t have copied the tag and the equations in the correct places.

    You’ve entered the div tag into the “Set Equation” attribute of the calculated field, and the equation in the content of the “HTML Content” field.

    Furthermore, you are not using the correct quote symbols.

    The following tag includes the valid double quote symbols:

    <div class="result-here"></div>

    But you’ve entered this:

    <div class=”result-here”></div>

    Best regards.

    Thread Starter kapdev

    (@kapdev)

    You’re right! I had it right at first but changed it since I thought it was backwards after reading the message. It worked! Thank you so much!

    Thread Starter kapdev

    (@kapdev)

    If I need to do this for many fieldnames, can I use the same function with only one HTML content, or do I need to create an HTML content field with a different class name for each one?

    I tried copying the same formula into a sister page I am working on, but it didn’t work. I have attached the link.

    • This reply was modified 3 years, 5 months ago by kapdev.
    Plugin Author codepeople

    (@codepeople)

    Hello @kapdev

    The issue is simple, you have forgotten the semicolon symbol at the end of the line of code:

    else result = "2 tabletas BUCODISPERSABLES de 4 mg vía oral, una sola dosis. Dejar que se disuelvan en la boca. Puede repetir la dosis en 12 horas en caso necesario"

    The correct equation would be:

    
    (function(){
    var result = '';
    
    if(fieldname2 < 10) result = "No se recomienda este medicamento por no poderse partir la pastilla";
    else if(fieldname2 <= 40) result = "1 tableta BUCODISPERSABLE de 4 mg vía oral, una sola dosis. Dejar que se disuelva en la boca. Puede repetir la dosis en 12 horas en caso necesario";
    else result = "2 tabletas BUCODISPERSABLES de 4 mg vía oral, una sola dosis.  Dejar que se disuelvan en la boca. Puede repetir la dosis en 12 horas en caso necesario";
    
    jQuery('.result-here').html(result);
    return result;
    })()

    Best regards

    Thread Starter kapdev

    (@kapdev)

    Thank you so much for speedy and effective service!

    This worked, but the text isn’t wrapping. It is displaying as one line only, better appreciated on a mobile phone.

    How can I apply this to other fields with the same issue (Long sentences as result of the equation)?

    • This reply was modified 3 years, 5 months ago by kapdev.
    Plugin Author codepeople

    (@codepeople)

    Hello @kapdev

    The equations check the value of the fieldname2 field, but the value of a disabled field is zero. So, you must check the value of the fieldname2 be valid as follows:

    (function(){
    var result = '';
    
    if(fieldname2)
    {
        if(fieldname2 < 10) result = "No se recomienda este medicamento por no poderse partir la pastilla";
        else if(fieldname2 <= 40) result = "1 tableta BUCODISPERSABLE de 4 mg vía oral, una sola dosis. Dejar que se disuelva en la boca. Puede repetir la dosis en 12 horas en caso necesario";
        else result = "2 tabletas BUCODISPERSABLES de 4 mg vía oral, una sola dosis.  Dejar que se disuelvan en la boca. Puede repetir la dosis en 12 horas en caso necesario";
    }
    jQuery('.result-here').html(result);
    return result;
    })()

    Best regards.

    Thread Starter kapdev

    (@kapdev)

    Thanks, I am having two issues:

    1. Text is still not wrapping despite the HTML workaround (may best be seen on mobile phone). Only one line is displayed
    2. I don’t know how to apply this to other fieldnames as there are several fieldnames with the same issue and needing to wrap text to be able to read entire result.

    Plugin Author codepeople

    (@codepeople)

    Hello @kapdev

    If your equations’ results are long texts and you want to adjust them in small screens, you must use the calculated field as an auxiliary but display the result in another tag just as you did throughout this thread.

    If you have multiple calculated fields in the form, but only one of them is active at once, you can use the same tag to display the results: jQuery('.result-here').html(result);

    Best regards.

Viewing 15 replies - 1 through 15 (of 30 total)
  • The topic ‘Wrapping Text Calculated Field’ is closed to new replies.