You are viewing limited content. For full access, please sign in.

Question

Question

Disable formula

asked on January 27, 2021

Hi,

How can I disable or modify the formula of a field using javascript?

 

Thanks,

0 0

Replies

replied on January 28, 2021 Show version history

Hi Luis

 

This is my method to sum 2 fields when checkbox is checked (formula) or to write something when is not checked (not formula) using Javascript (and only javascript, no formula !)

 

//When document is ready
$(document).ready(function() {
 
  //DO check_formula when the document is ready
  check_formula();
  
  //DO check_formula when the checkbox change
  $('#Field4-0').change(function()
	{
    	check_formula();
  	});
  
})

//Check_formula
function check_formula(){
  	
  	//Get Checkbox
  	var checkBox = document.getElementById("Field4-0");
          	
    // If the checkbox is checked, execute the formula
  	if (checkBox.checked == true){
    	
      	//GET Field 1 and Field 2
      	var field1 = $('#q1 input').val();
      	var field2 = $('#q2 input').val();
      
      	//Change STRING to INT
      	field1 = parseInt(field1);
        field2 = parseInt(field2);
          
        //SUM Field1 and Field2  
      	var total  = field1 + field2;
      
      	//SET Field Total
      	$('#q3 input').val(total);
      
  	} else {
    	
      	//SET Field Total = "No formula"
      	$('#q3 input').val("No Formula");
      
  	}
}

You need to know how to get ID or Class Name for each element.

1 0
replied on January 28, 2021

Hi Olivier,

Yes, programming the formula in javascript is an alternative, but we want to try to configure the calculation only with the native formulas.

Regards,

0 0
replied on January 27, 2021

What is the reason for changing  or disabling the formula?

0 0
replied on January 28, 2021

Hi Steve,

 

Because Forms shows an error when submitting the form and the formula has no result.

1 0
replied on January 28, 2021 Show version history

Unfortunately LF doesn't support ERR so I'd look for a way to make it an IF calculation instead, such as

=IF(Var1="","",Your calculation)

or

=IF(AND(Var1="",VAR2=""),"",Your calculation)

The way when the fields are empty the value is "" which is a result, otherwise when the field has a value it runs the calculation.

2 0
replied on January 28, 2021

IF the output is a number field then I would return 0 instead

 

=IF(Var1="",0,Your calculation)

or

=IF(AND(Var1="",VAR2=""),0,Your calculation)

2 0
replied on January 28, 2021 Show version history

You are fast Steve XD

This is mine (still using my Print Screen)

=IF(Choice.Activate_Formula,SUM(Field_1,Field_2),"Return String")

(Put this formula inside the Field Total)

1 0
replied on January 28, 2021

Yes, that was another option that we were analyzing. The form has approximately 200 formulas, so it is difficult to add the IF to each one. Anyway, thank you both.

0 0
replied on January 28, 2021

Have you tried just turning off Field Validation for the form?

0 0
You are not allowed to follow up in this post.

Sign in to reply to this post.