Specify input value based on segmented control

I have a form that is partly populated based on values in a selected row of a table. There are 2 controls in particular that I am struggling with:

Segmented control (called PostSpecificSeg) has the options:

  • Not Post Specific (value = "generic")
  • Post Specific (value = "specific")

Text input (called PostIDtoUse)

What I am trying to get to is:
when "Not Post Specific" is selected (PostSpecificSeg = "generic") then PostIDtoUse should be null.
when "Post Specific" is selected (PostSpecificSeg = "specific") then PostIDtoUse should be the value of post_id in the selected row of dataTable.

I am using 2 event handlers in PostSpecificSeg as follows:
event 1
Action: Control component
Component: PostIDtoUse (Text Input)
Method: Clear value
Only run when: {{ PostSpecificSeg.value = "generic" }}

event 2
Action: Control component
Component: PostIDtoUse (TextInput)
Method: Set value
Value: {{ dataTable.selectedRow.post_id }}
Only run when: {{ PostSpecificSeg.value = "specific" }}

event 2 runs regardless of which value is selected in PostSpecificSeg, and event 1 never runs.

What am I doing wrong?

Hey @lburmz

I noticed that the issue with your form might be in the logical conditions used for the event handlers

  • Clear Value when "Not Post Specific" is selected:

    • Action: Control component
    • Component: PostIDtoUse (Text Input)
    • Method: Clear value
    • Only run when: {{ PostSpecificSeg.value === "generic" }}
  • Set Value when "Post Specific" is selected:

    • Action: Control component
    • Component: PostIDtoUse (Text Input)
    • Method: Set value
    • Value: {{ dataTable.selectedRow.post_id }}
    • Only run when: {{ PostSpecificSeg.value === "specific" }}

Ensure you use the === operator for strict comparison.

This should help resolve the issue!

Thank you for helping the obvious beginner!! :slight_smile:

1 Like