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

Add visibility conditions to forms #18496

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

AdrienClairembault
Copy link
Contributor

@AdrienClairembault AdrienClairembault commented Dec 6, 2024

Checklist before requesting a review

  • I have performed a self-review of my code.
  • I have added tests that prove my fix is effective or that my feature works.

Video

conditions1

Description

"Minimum" implementation of the visibility condition editor (still a lot of code was required).

Features

  • Pick a visibility for question/section/comments (Always visible, Visible if... or Hidden if).
  • When the visibility is Visible if... or Hidden if, the condition editor is displayed.
  • The editor allow conditions to be configured using 4 criteria:
    • Logic operator (And or Or, not available on the first condition)
    • Item (for now, only Short answer questions are selectable here but all questions will be in the future, as well as sections and comments)
    • Value operator (the value depends on the selected item, e.g. Is equals to, Is not equals to, Contains and Do not contains for Short answer questions).
    • Value (the displayed input type will change depending on the item + the value operator, e.g. a simple <input type="text"> for Short answer questions).
  • Conditions can be deleted using the trashcan icon.

Note that conditions are not yet applied when the form is rendered for an end user.

UI

The condition editor is available using a small dropdown that is only shown when the question is selected.
The name of the dropdown reflect the current visibility strategy, allowing users to quickly see which questions have conditions.

image

In the editor, inputs are grouped by color to help visualize the conditions:

image

Technical constraints

The difficult part here is to always display a valid editor when the dropdown is opened.
Indeed, the editor contains references to some forms items like questions, which may be modified or deleted at any time.
New questions may also be added and should be available in the editor.

We can't rely on the server state to display the editor (as the client state may be modified and not yet saved) and we also can't rely on the client to render the content as we don't use vue here.

The simplest way to handle this is to send the state to the server each time the editor is opened, which will return the rendered content that we can then insert into the DOM (kinda a simplified homemade "live component") .
Any action on the editor that impact the rendering (picking an item or deleting a condition) will also trigger the same re-render behavior.

@AdrienClairembault AdrienClairembault self-assigned this Dec 6, 2024
@AdrienClairembault AdrienClairembault changed the title Add visibility conditions to questions Add visibility conditions to forms Dec 9, 2024
@AdrienClairembault AdrienClairembault marked this pull request as ready for review December 9, 2024 14:44
@orthagh
Copy link
Contributor

orthagh commented Dec 9, 2024

deprecated ?

image

Copy link
Contributor

@trasher trasher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment

@AdrienClairembault
Copy link
Contributor Author

AdrienClairembault commented Dec 18, 2024

I didn't reproduce the error but it should be fixed now.

I've also applied the UI changes you suggested:

image

Copy link
Contributor

@trasher trasher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Please rebase to solve conflicts and see if tests are still ok now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants