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

Question

Question

"As new rows" via jQuery

asked on November 29, 2022

I have a form with a Lookup Rule that populates a field in a table. This works as intended, where in each row the user gets to pick a choice from all values returned. I would like to add a button or checkbox that triggers the "as new rows" logic, populating all Lookup Rule values into its own row in the table.

Is there jQuery code that would do this? Otherwise, is there another way to do this? I would like to keep the "as new rows" off by default and only turn on by clicking a button or checking a box.

Thanks,

0 0

Answer

SELECTED ANSWER
replied on November 29, 2022

I don't think there's any way to change that behavior on the client side (i.e., via JavaScript) at runtime since that is part of the lookup configuration.

You may need to create two separate lookup rules and use JavaScript/jQuery, then you could have a hidden field that you populate with code to trigger the rule.

The catch is that triggering a lookup rule is probably going to reset the table, but whether or not that is an actual problem depends on your specific scenario.

1 0
replied on November 30, 2022

Thanks, Jason. This worked great!

0 0

Replies

replied on November 29, 2022

There are listeners in Forms for when a field is changed, and when lookup rules are done running. You can even use event ID of specific lookup rules so a JavaScript function only runs when a specific lookup rule runs. 

Lookup rules will run if you do $(.field-class type).change(); on a field related to a particular lookup rule. I think you should be able to bash something together that way. 

However, I've never found a way to run a lookup rule that doesn't replace all the data from the previous lookup. You'd have to find some way to save the contents of the table each time a new select is made, and when a new selection is made wait until the lookup rules are done running, and then load the saved rows back into the table all over again. 

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

Sign in to reply to this post.