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

Hidden field can never be required. Skip that validation #716

Merged
merged 4 commits into from
Mar 12, 2025

Conversation

chiragchhatrala
Copy link
Collaborator

@chiragchhatrala chiragchhatrala commented Mar 4, 2025

Summary by CodeRabbit

  • Form Validation Improvements

    • Adjusted form validation to exclude hidden fields from being marked as required.
  • User Interface

    • Added descriptive text in the form editor to clarify actions triggered by conditions.
    • Included a note indicating that hidden fields can never be required.
  • Tests

    • Introduced a new test case to verify that validation skips fields hidden by logic conditions.

@chiragchhatrala chiragchhatrala requested a review from JhumanJ March 4, 2025 08:48
Copy link
Contributor

coderabbitai bot commented Mar 4, 2025

Walkthrough

This pull request updates the backend validation logic in the AnswerFormRequest by adding an extra condition to exclude hidden properties from being marked as required. Additionally, two new paragraph elements are introduced in the FormBlockLogicEditor.vue to inform users that hidden fields cannot be required. There are no changes to public or exported entity declarations.

Changes

File(s) Change Summary
api/.../AnswerFormRequest.php Modified the rules() method to include an extra condition that skips properties marked as hidden when determining if they are required.
client/.../FormBlockLogicEditor.vue Added two new paragraph elements to inform users about actions triggered by conditions and that hidden fields can never be required. Removed the previous help attribute from flat-select-input.
api/.../FormLogicTest.php Added a new test case to verify that validation skips fields hidden by logic conditions, ensuring correct behavior when fields are conditionally displayed.

Possibly related PRs

Suggested reviewers

  • JhumanJ

Poem

I'm a little rabbit in the code,
Hopping through logic on a happy road.
Hidden fields now step aside,
With alerts and checks working side-by-side.
Leaping over bugs with a joyful stride! 🐇✨


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d9fcda0 and 863c5c5.

📒 Files selected for processing (2)
  • api/app/Http/Requests/AnswerFormRequest.php (1 hunks)
  • api/tests/Feature/Forms/FormLogicTest.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • api/app/Http/Requests/AnswerFormRequest.php
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build the Nuxt app
🔇 Additional comments (1)
api/tests/Feature/Forms/FormLogicTest.php (1)

547-609: Well-structured test case that verifies hidden fields are not validated as required.

This test case effectively validates the core functionality mentioned in the PR title: ensuring that fields hidden by logic conditions aren't required during form validation. The test properly covers both scenarios:

  1. When the email field is empty, the title field is hidden and submission succeeds despite the title being marked as required.
  2. When the email field contains a value, the title field becomes visible and submission fails because the required field is missing.

The test structure follows established patterns in the file and includes clear comments describing the test flow.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue (1)

297-303: Existing logic conflicts with the new rule

I notice that the current logic handling for multiple actions in onActionInput() already attempts to prevent the contradictory scenario of having both "hide-block" and "require-answer" actions together, which aligns with the new rule. However, it's implemented as an either-or choice rather than completely preventing "require-answer" when "hide-block" is selected.

Since the backend now enforces that hidden fields cannot be required, it might be better to update the UI to disable the "Require answer" option entirely when "Hide Block" is selected.

You could consider modifying the actionOptions computed property to dynamically exclude the "Require answer" option when "hide-block" is in the selected actions:

actionOptions() {
  // Existing code...
  
  if (this.field.hidden) {
    return [
      { name: "Show Block", value: "show-block" },
-     { name: "Require answer", value: "require-answer" },
    ]
  } else if (this.field.disabled) {
    // Existing code...
  } else {
+   const actions = [
+     { name: "Hide Block", value: "hide-block" },
+     { name: "Disable Block", value: "disable-block" },
+   ];
+   
+   // Only add "Require answer" option if "hide-block" is not selected
+   if (!this.logic.actions.includes("hide-block")) {
+     actions.push(this.field.required
+       ? { name: "Make it optional", value: "make-it-optional" }
+       : { name: "Require answer", value: "require-answer" }
+     );
+   }
+   
+   return actions;
-   return [
-     { name: "Hide Block", value: "hide-block" },
-     { name: "Disable Block", value: "disable-block" },
-     this.field.required
-       ? { name: "Make it optional", value: "make-it-optional" }
-       : {
-           name: "Require answer",
-           value: "require-answer",
-         },
-   ]
  }
}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b633f97 and a337efc.

📒 Files selected for processing (2)
  • api/app/Http/Requests/AnswerFormRequest.php (1 hunks)
  • client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Build the Nuxt app
🔇 Additional comments (2)
api/app/Http/Requests/AnswerFormRequest.php (1)

90-90: Logical improvement: Skip validation for hidden fields

The addition of the condition (!isset($property['hidden']) || !$property['hidden']) properly ensures that hidden fields will never be marked as required, preventing a paradoxical situation where users would be required to fill out fields they can't see.

This change correctly implements the described PR objective and handles both cases where the 'hidden' property is explicitly set to true or not set at all.

client/components/open/forms/components/form-logic-components/FormBlockLogicEditor.vue (1)

60-66: Good UX enhancement: Clear notification about hidden field behavior

The added alert provides users with clear information about the constraint that hidden fields cannot be required. This aligns perfectly with the backend validation logic change and helps prevent user confusion.

The styling choices (yellow color, information icon, subtle variant) appropriately convey this as informational guidance rather than an error or warning.

Copy link
Owner

@JhumanJ JhumanJ left a comment

Choose a reason for hiding this comment

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

Please check other PR

- Replace UAlert with plain text description
- Update action description text
- Remove help text from select input
- Simplify note about hidden field requirements
- Implement test case for fields hidden by logic conditions
- Update AnswerFormRequest to use new FormLogicPropertyResolver method for hidden field check
- Ensure required fields are skipped when hidden by form logic
@chiragchhatrala
Copy link
Collaborator Author

Please check other PR

Done

@chiragchhatrala chiragchhatrala requested a review from JhumanJ March 6, 2025 11:09
@JhumanJ JhumanJ merged commit 7b94299 into main Mar 12, 2025
7 checks passed
@JhumanJ JhumanJ deleted the 1a2a6-can’t-be-hidden-&-required branch March 12, 2025 06:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants