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

Discussion

Discussion

Forms - How do you populate a field with existing value without losing the choices?

posted on July 7, 2020 Show version history

I have a lookup rule to populate a field with a previously set value. So the value of the field becomes say "Test" after the lookup runs.

But if the user want's to change the value, it does not display the entire list of values.

I tried using a Drop Down and a Single Line with Auto Suggestions. In both cases, after the lookup runs and populates the existing value, all the suggestions/or options are lost.

0 0
replied on July 8, 2020

You will need to fill them into separate fields: one for the list (a dropdown) and a hidden one for the value (a single line). Then use JavaScript to copy the value from the hidden field to the list field.

$(document).on("change", "#q2 input", function() {
  $("#q1 select").val($("#q2 input").val()).change();
});

In the above code q1 is the dropdown, q2 is the hidden single line.

1 0
replied on July 9, 2020

Thanks Jim

I did end up doing this because I had no other choice, but it makes the form much more complex for someone to understand why there is all these hidden fields and javascript just for a lookup while working on the form.

I try to minimize the javascript to only custom features and use lookups/field rules as much as possible.

0 0
replied on July 9, 2020

It definitely does make it more complex, but unfortunately it's the only way I've found of doing it.

0 0
replied on July 9, 2020

Ok, ill keep going forward with it. Careful doing that way though, if the value doesn't change with a new lookup your .on('change' method will not fire. So if the user changes that field for another reason, then, later pulls another lookup which happens to return the same value, the field will show the wrong value.

So mine is even more confusing with a dispatching function called which resets hidden fields and triggers the lookup afterwards.

0 0
replied on July 9, 2020

True, that would not change it. I didn't know what exactly your form looked like so I can only account for so much! That sounds like quite a pain.

0 0
replied on July 8, 2020

The value user entered in previous step has highest priority so lookup value will not be populated. You want to populate the lookup values on field with existing value for dropdown in order to allow user to select from the list again?

0 0
replied on July 9, 2020

Yes exactly, I want a list of values to choose from and the current value to be whatever is currently set in the database.

0 0
replied on July 10, 2020

The lookup rule without condition will be executed when load the form even when the field has a value submitted in previous step. But lookup rule with condition won't be executed when load the form when the field already has a value submitted in previous step. So you use lookup rule with condition and the lookup return multiple values?

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

Sign in to reply to this post.