• Resolved suaveyg

    (@suaveyg)


    I am creating a simple calculator form which based on result, will show default hidden fields. The form is set to dynamically evaluate the equations for all number fields. I also have a calculate button that I am trying to complete an onclick function for showing these default hidden fields based on the calculated result of a different field. I can seem to get this successfully working by using tools like JSfiddle… i can also use tools to validate that my js is valid.. but it still will not work as expected when adding to the calculate button onclick event area.

    if i try and dramatically simplify my if/else conditional logic to to the example below, this logic will not work on the button. Result even if the value of netcashflow is higher than 0 will return neutral as a result. I am lost on why this is. I have also validated using alerts that my variable has a correct value.

    var netcashflow = document.getElementById(‘fieldname26_1’).value;
    if(netcashflow>0){
    return alert (“positive”);
    }
    else {
    return alert (“neutral”);
    }

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

    (@codepeople)

    Hello @suaveyg

    Could you please include the link to the page that contains the form and indicate which fields you want to display based on the equations’ results?

    Please, note that if you used the "Hidden" control or "Calculated Field" control with the choice “Hide Field From the Public Page” ticked, the plugin creates them with <input type="hidden"> tags. An input tag with type="hidden" cannot become visible. In this case, the alternative would be to assign the hide class name into the “Add CSS Layout Keywords” attribute of the field calculated field you want to make visible by code.

    Best regards.

    Thread Starter suaveyg

    (@suaveyg)

    Thank you for your response. the page link is : https://designingote.com/bcfc/

    one of the methods I was going to use was the hide class followed by the code:(“.classname”).removeClass(“hide”);

    but at the moment, the conditional statement won’t even work as expected before I customize the actions.

    I was looking to get the value of fieldname26 and based on that value, i would hide/show fieldname20 through to fieldname22.

    So if fieldname26 was greater than 0, then display fieldname20(class .poscf)

    if fieldname26 was less than 0, then display fieldname21(class .negcf)

    if fieldname26 was equal to 0, then display fieldname22(class .neucf)

    fields 20 through to 22 would be hidden by default by either using css display: none or the suggestion you mentioned which was the hide class.

    calculation would be on the calculate button (fieldname19) where all of this would take place.

    Cheers!

    Plugin Author codepeople

    (@codepeople)

    Hello @suaveyg

    I’ll assume you want only to show/hide the fields and not activate/ignore them. So, I’ll use the SHOWFIELD and HIDEFIELD operations (To activate/ignore fields you should use the ACTIVATEFIELD and IGNOREFIELD operations, respectively)

    Insert a calculated field as an auxiliary field in the form, that you can configure as hidden by ticking a checkbox in its settings, and enter the equation:

    (function(){
    HIDEFIELD(fieldname20|n);
    HIDEFIELD(fieldname21|n);
    HIDEFIELD(fieldname22|n);
    
    if(0<fieldname26) SHOWFIELD(fieldname20|n);
    if(fieldname26<0) SHOWFIELD(fieldname21|n);
    if(fieldname26==0)SHOWFIELD(fieldname22|n);
    })()

    Best regards.

    Thread Starter suaveyg

    (@suaveyg)

    I have tried the auxiliary approach, and that works as you have mentioned in a dynamic way. However, I was trying to get the conditional logic working on a calculate button (fieldname 19) where the function will only initiate on an onclick event. That has been my struggle up to this point to get working. Is it still possible to utilize this showfield/hidefield concept on this calculate button type? After trying to implement pieces of this concept on the button, it will not work in any way expected.

    Very much appreciating your help codepeople

    Cheers!

    Plugin Author codepeople

    (@codepeople)

    Hello @suaveyg

    If you want to implement the code below as the onclick event of the button:

    (function(){
    HIDEFIELD(fieldname20|n);
    HIDEFIELD(fieldname21|n);
    HIDEFIELD(fieldname22|n);
    
    if(0<fieldname26) SHOWFIELD(fieldname20|n);
    if(fieldname26<0) SHOWFIELD(fieldname21|n);
    if(fieldname26==0)SHOWFIELD(fieldname22|n);
    })()

    Since you cannot access the fields’ values by their names outside the context of the equations, you must use the getField operation and its val method.

    The onclick event would be:

    
    HIDEFIELD('fieldname20');
    HIDEFIELD('fieldname21');
    HIDEFIELD('fieldname22');
    
    let v = getField('fieldname26').val();
    if(0<v) SHOWFIELD('fieldname20');
    if(v<0) SHOWFIELD('fieldname21');
    if(v==0)SHOWFIELD('fieldname22');

    Best regards.

Viewing 5 replies - 1 through 5 (of 5 total)

The topic ‘If/Else statement for hiding/showing fields using calculate button’ is closed to new replies.