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

Question

Question

Forms Designer v12 onsite JS LFForms need help removing options after lookup rule and field formula run

asked on March 10

I have a form with a three hidden fields that show TRUE or FALSE depending on whether a particular type of submission is possible. 

The hidden fields look at three different tables populated by lookup rules. If the table has rows the hidden field shows true for that list. The hidden fields use an Advanced Formula to see if there are one or more rows in each of the three tables. This works great with my field rules. HTML fields with the "you can't do this' message show or hide like they're supposed to.

To make the form as foolproof as possible I want to use LFForms.changeFieldOptions to remove options from a radio button if the hidden field for that option says 'FALSE'. 

But it seems to get stuck on FALSE and always removes the option. I think the error is something to do with the onFieldChange, but I'm stumped. 

LFForm.onFieldChange(() => optionPendingShow() , {variableName: "HAS_PENDING_TRANSACTIONS"});


function optionPendingShow() {
	let newTF = LFForm.getFieldValues({fieldId: 155});
	if (newTF = "FALSE") {
		LFForm.changeFieldOptions( { fieldId: 125 }, ["Submit transaction receipt and coding"], "remove" );
    }
}

 

0 0

Answer

SELECTED ANSWER
replied on March 11 Show version history

I believe the issue is not in line 9, as @████████indicated, but in the if statement.

Change

if (newTF = "FALSE") {

to

if (newTF == "FALSE") {

 

In JavaScript, the "Equal To" comparison is represented by == or for strict comparison, it is ===

3 0
replied on March 11

I'd go a step further and say always use ===. On line 5 if you set the variable newTF using 

const newTF = LFForm.getFieldValues({fieldId: 155});

You'd immediately hit an error on the next line which would let you know you need to use an equality check and not try to re-set a variable thats already been declared.

2 0
replied on March 11

ARGH!!! I knew it was something stupid! 

0 0
replied on March 18

I fixed the code, but it still doesn't work right. I love almost everything about Modern Designer, but doing JS with it is a trial. I think it's a timing issue with the multiple sets of field formulae and lookup rules that messes it up. 

I need to settle for less than perfect and get the project done and out the door. :) 

0 0
replied on March 18

For this type of interaction, you'd have the same issues in classic as in modern. 

If for some reason your TRUE/FALSE field is flipping very quickly because of formulas and lookups you should debounce the function so it only fires once the event settles down. Technically your change event if fired in quick succession could only preserve the first call instead of the second with the value you actually care about.

1 0
replied on May 7

I figured out how to do it by changing my approach. The form is populated from database views, and I was trying to use JS or Field Formulas when the better and more correct solution was to use a SQL Stored Procedure that returns True or False depending on whether the SQL views had records to show. 

Then fill in a hidden field on the form from that Stored Procedure, and use that to trigger the field rules. Not exactly simple, but it works great. 

0 0

Replies

replied on March 11 Show version history

Replace this "}"  at the end of your code with.

});

This needs to be closed. Try  this first and lets go from there.

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

Sign in to reply to this post.