How to set field value in Form component - UI Builder
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-20-2024 06:29 AM
Hello,
I'm trying to do simple thing in UI Builder but I cannot find a solution that will work correctly.
On my form I have two fields: select box and text field. Based on the selection in select box I want to automatically populate a text field with some value and later save it with custom button by triggering Save action from the form data resource.
Is there any way I can achieve above?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-19-2024 02:29 AM
I don't quite follow why you can't do this with a client script (normal sys_client_script, not UI Builder client script) on the table that you are passing to the form component? But assuming that you can't do that for some reason the below may help.
If your page has the out of the box form component then it will also have a form controller. The form controller presents events that you can trigger including things like "Set a field value".
More normally you might do this from another component like a modal or something, but in this case you will add a form event mapping to a form event handler.
So in the config panel for your form you want to Add an event mapping for "Form value set" (pink in the screenshot below) and then in that mapping add an event handler "Set form value" (orange in the screenshot below)
You'll also need to add a condition once you've set up the event and evaluate the event payload to check that the field that changed was the right one.
But I think that really this quite a strange solution and it should be possible to do it with Client script like you would in the core UI.
Hope that helps