Events and Actions - Conditional OnChange event?

I’m trying to think of the best way to do something that is probably easy, but seems more convoluted than it probably has to be—so I am probably missing an easy solution… On one of my pages, if the user checks a box to copy the address from one set of qodly source address fields (street,city,ST,zip) to another set of qodly source address fields on the page, the fields are to be copied. ie: if user checks the checkbox for copy the statements mailing address to the taxdocs mailing address, the qodly source data is copied into the taxdocs address fields. Is there an easy way to do: onchange event: if checkbox value changes to true onchange, copy the address fields from one set of qodly sources to the other, else clear the field values in the other. Thx for ideas. Solution is probably super easy, I just cant see it for some reason.

Hello Robert,

One possible solution is to implement this logic in a function that dynamically updates the destination field based on the checkbox state.

You can create a function that accepts the boolean qodly source linked to the checkbox and the string to copy as parameters. Inside the function, check if the boolean is true; if so, return the copied value; otherwise, return an empty string (indicating a cleared destination). The function’s output should be bound to the destination qodlysource, which will then contain the copied value.
This function should be linked to the onChange event of the checkbox input component to ensure that the destination qodlysource is updated whenever the checkbox is toggled…

resetCopy

Hope this is clear and aligns with what you were asking for!

Thanks! I thought that would require like 6 functions to execute after the onchange event so was wondering if easier way. The trick is that each function result only can update a single qodly source. Its doable as 6 functions onchange, but wondered if easier way. I ended up changing the statments address and the taxdocs address into objects both in the model and on the webform with street, city, state etc. as attributes. then just returned the single updated taxdocs address object as needed onchange. Both ways workable, but would be neat if a function result could update multiple qodly sources on the page. Appreciate help!

Hi @musseman,

We of course encountered such use cases during Qodly Studio implementation. Of course setting up 6 onChange event is not desirable. But it is quite hard to have a function returning several values at once :slight_smile: Unless indeed you encapsulate such returned values in an object, like you did.

I think you designed your Page properly then.

Back-end functions have no knowledge of your Page’s Qodly Sources. If they were, your code updating them would end up not being MVC compliant as it would be too tied up with front-end.

Using an object in this case is a better approach in our opinion.
Note that you should be able to do so without changing your model, and use an object only to describe and validate your front Page, and write an entity or update or save fonction that takes your object and apply values to your entity, independently of how it is modelized.

1 Like