WordPress.org

Forums

Calculated Fields Form
[resolved] Text output (21 posts)

  1. angie1357
    Member
    Posted 1 year ago #

    I have 3 different products and i've assigned the value 1, 2, & 3 to them as hidden field types.

    The user needs to be able to tick a feature and the output will tell them which product to get.

    I found a thread about changing the code in the module_public.js to then output the text:

    return isFinite( v ) || /\d{2}[\/\-\.]\d{2}[\/\-\.]\d{4}/.test( v ) || /Professional Website|Premium Website|Ultimate Website/i.test( v );

    This seems to work, but it's only picking up the first text, "Professional Website"

    My calculated field equation looks like this:

    (function(){

    if(fieldname1 <= 1) return fieldname4;

    if(fieldname1 <= 2) return fieldname6;

    if(fieldname1 <= 3) return fieldname7;

    })();

    (function(){

    if(fieldname4 <= 1) return "Professional Website";

    if(fieldname6 <=2) return "Premium Website";

    if(fieldname7 <= 3) return "Ultimate Website";

    })();

    Please can you tell me where i'm going wrong?

    Thanks
    Angie

    https://wordpress.org/plugins/calculated-fields-form/

  2. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    You can use the following validation rules:

    return isFinite( v ) || /\d{2}[\/\-\.]\d{2}[\/\-\.]\d{4}/.test( v ) || /((Professional\s+Website)|(Premium\s+Website)|(Ultimate\s+Website))/i.test( v );

    or simply replace all the validation rule like follow:

    return (typeof v != 'undefined');

    Best regards.

  3. angie1357
    Member
    Posted 1 year ago #

    Thanks for your quick response. it seems like i've finally got it working - to an extent.

    What i now need to figure out is to get it to output only the highest value as well as to hide the outputs that pull through below the Recommended Website Package field.

    http://showmeonlinemedia.co.za/test/

  4. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    I don't know exactly the behavior you want in the form, but if you want hide some fields of the form, you only should add an class name to the fields to hide, through the "Add Css Layout Keywords" attribute, for example: my_class, and then define the new class in any of CSS files of your website:

    .my_class{display:none;}

    Best regards.

  5. angie1357
    Member
    Posted 1 year ago #

    thanks, i've done that ans it works well, but how do I make the output the highest number and not the lowest.

    For example, if someone has ticked 3 boxes, one with the 1 value, and two with the 2 value, when they push calculate, it says the result is 1 (I want it to pick the highest number and output that).

    I have tried 'max(fieldname19,fieldname20,fieldname21)' but this did not work.

    Please advise, thanks agian

  6. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    The use of the operation "max" is correct, and should return the maximum of the three fields. Could you tell where are you using the max operation, please? I've checked your form in:

    http://showmeonlinemedia.co.za/test/

    and I can't detect where the operation is used.

    Best regards.

  7. angie1357
    Member
    Posted 1 year ago #

    I had taken it out beacuse when i put the max(fieldname19,fieldname20,fieldname21) into the equation box in the Calculated Field (recommended Website Package) t works, but it then only returns the value 1, 2 or 3, instead of the words/descriptions connected to the value, Proffesional, Premium, ultimate.

    Here is what my equation currently looks like: (including the max)

    (function(){

    if(fieldname1 <= 1) return fieldname19;

    if(fieldname1 <= 2) return fieldname20;

    if(fieldname1 <= 3) return fieldname21;

    })();

    (function(){

    if(fieldname19) return "Professional Website";

    if(fieldname20) return "Premium Website";

    if(fieldname21) return "Ultimate Website";

    })();

    max(fieldname19,fieldname20,fieldname21)

  8. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    You have not created an equation, You have merged three equations in one. First, you should determine of the value that you want display in the calculated field, if you want display only the maximum value between fieldname19, fieldname20 and fieldname21, the equation is simply:

    max(fieldname19,fieldname20,fieldname21)

    Best regards.

  9. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    Analyzing your form again, I think you have complicated your form too much, because if you use radiobuttons, in place of checkboxes, in the field: "How many pages do you need?", all will be reduced to the equation:

    (function(){
    if(fieldname19) return "Professional Website";
    if(fieldname20) return "Premium Website";
    if(fieldname21) return "Ultimate Website";
    })();

    You are trying to simulate an exclusive selection, but with checkboxes, the correct control in this case is the radiobutton.

    Best regards.

  10. angie1357
    Member
    Posted 1 year ago #

    Hmmm...ok, i've changed the pages one to radio buttons.

    If i use just this equation:
    max(fieldname19,fieldname20,fieldname21)
    Then it shows only the number value, 1,2,3 (correctly the highest one)

    If i use just this equation:
    (function(){
    if(fieldname19) return "Professional Website";
    if(fieldname20) return "Premium Website";
    if(fieldname21) return "Ultimate Website";
    })();
    Then all results are "Professional"

    How do I combine this in one equation, to choose the highest value and then convert it into the description of it?

    Thanks :-)

  11. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    If you want combine both equations the solution would be:

    (function(){
    var m = MAX(fieldname19, fieldname20, fieldname21);
    if(m==fieldname19) return "Professional Website";
    if(m=fieldname20) return "Premium Website";
    if(m==fieldname21) return "Ultimate Website";
    })();

    You are using now two equations associated to the calculated fields.

    Best regards.

  12. angie1357
    Member
    Posted 1 year ago #

    Thanks, but it does not work. It does not return any value now.

  13. angie1357
    Member
    Posted 1 year ago #

    Correction, it works! :-)

    there was a = missing in the equation

    Thanks again

  14. angie1357
    Member
    Posted 1 year ago #

    Is there a way that the output "recommended Website Package" field can stay empty until a checkbox is ticked? currently it is displaying the least value before anything has been ticked - which also then eliminates the need for the calculate button, as it is visibly calculating and outputting all the time.

  15. codepeople
    Member
    Plugin Author

    Posted 1 year ago #

    Hi,

    You can use conditional statements in the equations. For example, if you have 3 fields: fieldname1, fieldname2 and fieldname3, and you want display a value in the calculated field if at least one of previous fields includes a value, the equation would be:

    (function(){
    if(fieldname1 || fieldname2 || fieldname3)
    {
    //....
    }
    else
    {
    return '';
    }
    })()

    You should use the logic of the previous equation in your form.

    Best regards.

  16. angie1357
    Member
    Posted 12 months ago #

    Hi again, it has come to my attention that the plugin does not work in Firefox. Please advise how I can fix this? Thanks

  17. codepeople
    Member
    Plugin Author

    Posted 12 months ago #

    Hi,

    The plugin works perfectly in Firefox. Could you send me the link to your webpage to check it in detail, please? The form was removed from the page you sent me previously.

    Best regards.

  18. angie1357
    Member
    Posted 12 months ago #

    Sorry about that, here's the page: http://showmeonlinemedia.co.za/spec-site/

    Thanks

  19. angie1357
    Member
    Posted 12 months ago #

  20. codepeople
    Member
    Plugin Author

    Posted 12 months ago #

    Hi,

    The issue is not related with the plugin, the issue is provoked by changes you have made in the style.css file of form's template.

    Please, open the "http://showmeonlinemedia.co.za/wp-content/plugins/calculated-fields-form/templates/06/style.css" file, in the text editor your choice, and removes the style line:

    padding: 35px 30px;

    Remember to clear the browser's cache after edit the online files.

    Best regards.

  21. angie1357
    Member
    Posted 12 months ago #

    Thank you - all sorted :-)

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Calculated Fields Form
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic