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

    (@codepeople)

    Hi,

    In this case you should use conditional statements in your equation, for checking the values of fields.

    For example, suppose your form includes two fields fieldname1 and fieldname2, and you want to evaluate the equation if the values of fields are not empty. So, the equation would be similar to:

    (function(){
    if( !/^\s*$/.test(fieldname1) && !/^\s*$/.test(fieldname2) )
    {
    // The rest of the equation here
    }
    else
    {
    return ”;
    }
    })()

    Use the same logic in your equation.

    Best regards.

    Thread Starter 4Webs

    (@4webs)

    Thanks again! Great support! πŸ™‚

    The field that should shows the result is called fieldname1. The equalation is now set to:

    [ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]

    ((fieldname2+fieldname3)-((fieldname2+fieldname3-1428)*0.15+1212+(fieldname4+(fieldname5-(fieldname5*1/3))+fieldname6+fieldname7)))*50

    If i set the equalation to:

    (function(){
    if( !/^\s*$/.test(fieldname2) && !/^\s*$/.test(fieldname3) && !/^\s*$/.test(fieldname4) && !/^\s*$/.test(fieldname5) && !/^\s*$/.test(fieldname6) && !/^\s*$/.test(fieldname7))
    {
    ((fieldname2+fieldname3)-((fieldname2+fieldname3-1428)*0.15+1212+(fieldname4+(fieldname5-(fieldname5*1/3))+fieldname6+fieldname7)))*50
    }
    else
    {
    return '';
    }
    })()

    This still returns a negative value(because the fields arent filled in). Am i doing something wrong?

    Plugin Author codepeople

    (@codepeople)

    Hi,

    Use in this case the following equation:

    (function(){
    if( fieldname2 != 0 && fieldname3 != 0 && fieldname4 != 0 && fieldname5 != 0 && fieldname6 != 0 && fieldname7 != 0 )
    {

    return ((fieldname2+fieldname3)-((fieldname2+fieldname3-1428)*0.15+1212+(fieldname4+(fieldname5-(fieldname5*1/3))+fieldname6+fieldname7)))*50;

    }
    else
    {
    return ”;
    }
    })()

    Best regards.

    Thread Starter 4Webs

    (@4webs)

    Yet again, thanks for the great answer! πŸ™‚

    I wasn’t clear in my last post. The value of any field can be 0(zero). Now, with this equation if a field has 0(zero) as value the equation sees is as NULL(?) and returns nothing instead of the result. Any ideas? != ” doesn’t work.

    Thanks! πŸ™‚

    Plugin Author codepeople

    (@codepeople)

    Hi,

    In this case you should use a trick, because the “Calculated Fields Form” assumes that if a field is empty, its value is zero allowing evaluate equations, even with fields optionals.

    Please, assign a classname (for example myclass) to the requiered fields in the equation: fieldname2, fieldname3, fieldname4, fieldname5, fieldname6, fieldname7

    and now, the equation would be:

    (function(){
    if( jQuery(‘.myclass input’).map(function() { if(this.value==””) return this.id; }).get().join() == “” )
    {
    return ((fieldname2+fieldname3)-((fieldname2+fieldname3-1428)*0.15+1212+(fieldname4+(fieldname5-(fieldname5*1/3))+fieldname6+fieldname7)))*50;
    }
    return ”;
    })()

    If you need contract Our custom coding services to implement your equation. Please, contact us through our support page:

    http://wordpress.dwbooster.com/support

    Best regards.

    Thread Starter 4Webs

    (@4webs)

    Thank you for the clear answers!

    I’m back again.. I’m using the equation stated above. My customer now wants something different.

    Fields also can be empty, if a field is empty is counts as zero(0) in the equation. But, the result may only display if everything is filled in(huh?). So I was thinking if it’s possible to work with a button that says calculated now. What this button does is; It takes all filled in fields and puts it in the equation. All empty fields are put in the equation as zero(0). And then maybe a new page loads and the result wil be shown there. Is that possible?

    Thanks in advance! πŸ™‚

    Plugin Author codepeople

    (@codepeople)

    Hi,

    By default the plugin assumes that the fields have the value zero if the fields is empty. With the previous equation I sent you, the calculated field displays a value, only if at least a input field has a value defined. Now, Your equation’s requirements have changed, all fields must include a value, or the calculated field will be empty. In this case the previous equation should be transformed like follow:

    (function(){

    var flag = true;

    jQuery( ‘.myclass input’ ).each(function(){ if(/^\s*$/.test( this.value ) ){ flag = false; }});

    if( flag )
    {
    return ((fieldname2+fieldname3)-((fieldname2+fieldname3-1428)*0.15+1212+(fieldname4+(fieldname5-(fieldname5*1/3))+fieldname6+fieldname7)))*50;
    }
    return ”;
    })()

    I’m sorry, but I can’t create all the equations of your customer’s project for free. If you want hire our service to create your formulas, please contact us through our support page:

    http://wordpress.dwbooster.com/support

    If you want use a button for calculation, I recommend you to install the latest update of plugin, and insert a button control in your form. In the button control, select the option “Calculate” for the button type attribute, and if you want disable dynamic calculation, open the “Form Settings” tab, and uncheck the option: “Eval dynamically the equations associated to the calculated fields”

    Best regards.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Hide value untill everything is filled in’ is closed to new replies.