Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to remove the values of choice not selected #6297

Open
reveur-code opened this issue Sep 3, 2024 · 1 comment
Open

How to remove the values of choice not selected #6297

reveur-code opened this issue Sep 3, 2024 · 1 comment
Labels
community:reviewed Issue has been reviewed by the Label Studio Community Team.

Comments

@reveur-code
Copy link

image
Let say , i have 2 choices, each choice i have different other text area.
When i choose one option, other option related text should become empty.

When i change to instant , all the related data on cumulative should become empty (when i change to instant , cumulative startdate, enddate , duration should be empty.

@jombooth
Copy link
Contributor

jombooth commented Sep 4, 2024

Hi @reveur-code, please take this with a grain of salt, but our gen AI tool recommended this approach:

To achieve this behavior in Label Studio, you can use the visibleWhen attribute to control the visibility of the text areas based on the selected choice. Additionally, you can use the whenChoiceValue attribute to specify which choice should trigger the visibility of the text areas.
Here's an example configuration that demonstrates how to set this up:

<View>
  <!-- Choices for selecting Instant or Cumulative -->
  <Choices name="selection" toName="text" choice="single" showInline="true" required="true">
    <Choice value="Instant" />
    <Choice value="Cumulative" />
  </Choices>

  <!-- Text areas for Instant -->
  <View visibleWhen="choice-selected" whenTagName="selection" whenChoiceValue="Instant">
    <TextArea name="instant_text" toName="text" placeholder="Instant Text" />
  </View>

  <!-- Text areas for Cumulative -->
  <View visibleWhen="choice-selected" whenTagName="selection" whenChoiceValue="Cumulative">
    <TextArea name="cumulative_startdate" toName="text" placeholder="Cumulative Start Date" />
    <TextArea name="cumulative_enddate" toName="text" placeholder="Cumulative End Date" />
    <TextArea name="cumulative_duration" toName="text" placeholder="Cumulative Duration" />
  </View>
</View>

In this example:
The Choices tag allows the user to select either "Instant" or "Cumulative".
The TextArea tags for "Instant" are only visible when "Instant" is selected.
The TextArea tags for "Cumulative" are only visible when "Cumulative" is selected.
To ensure that the text areas related to the unselected choice are cleared when switching between choices, you can use the visibleWhen attribute to hide the text areas, which will automatically clear their values when they are hidden.
Explanation:
Choices Tag: This tag creates a set of radio buttons for selecting between "Instant" and "Cumulative".
TextArea Tags for Instant: These text areas are only visible when "Instant" is selected.
TextArea Tags for Cumulative: These text areas are only visible when "Cumulative" is selected.
When the user switches between "Instant" and "Cumulative", the text areas related to the unselected choice will be hidden and their values will be cleared.
Note:
Ensure that the toName attribute in the TextArea tags references an object tag in your configuration.
The visibleWhen attribute is used to control the visibility of the text areas based on the selected choice.
This setup will ensure that when you switch between "Instant" and "Cumulative", the related text areas for the unselected choice will be cleared.

@jombooth jombooth added the community:reviewed Issue has been reviewed by the Label Studio Community Team. label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
community:reviewed Issue has been reviewed by the Label Studio Community Team.
Projects
None yet
Development

No branches or pull requests

2 participants