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

Fix Captcha not rendering in bs modal #2055

Closed

Conversation

AbdiTolesa
Copy link
Contributor

@AbdiTolesa AbdiTolesa commented Oct 16, 2024

Fix https:/Strategy11/formidable-modal/issues/46

Relevant knowledge base

https://formidableforms.com/knowledgebase/bootstrap-modal/

Test Procedure

  1. Go to your Formidable Global settings > Catpcha, then configure and allow multiple captchas like this:
    CleanShot 2024-10-17 at 09 30 03@2x
    You can create reCaptcha keys here: https://www.google.com/recaptcha/
  2. Create a form and add fields to it.
  3. Create a WordPress page and add Formidable Modal block, select the block and add a Formidable Form block to the modal block. Then select the form you just created from the Formidable Form block options on the side bar.
  4. Save and Preview the wordpress page.
  5. Trigger the modal by clicking the modal trigger button.
  6. Confirm that the captcha is loaded in your form as in this screenshot and you should be able to submit the form.
image

Copy link
Contributor

coderabbitai bot commented Oct 16, 2024

Walkthrough

The pull request introduces modifications to the frmCaptcha function in js/formidable.js, enhancing the visibility checks for forms containing captchas. The updated logic first verifies the existence of the closest form and checks if it is displayed within a modal. If the form is in a modal, the captcha is rendered; otherwise, the original visibility check is applied. Additionally, a new function, frmAfterRecaptcha, is introduced to manage the submission process post-captcha validation.

Changes

File Change Summary
js/formidable.js - Updated frmCaptcha function to improve visibility checks for forms with captchas.
- Added frmAfterRecaptcha function to handle submission after captcha validation.

Possibly related PRs

  • Support fields validation with captcha #1961: This PR enhances the validation logic for forms with captcha, which is directly related to the changes made in the frmCaptcha function regarding captcha rendering based on form visibility.
  • Skip rendering captcha only if closest form is hidden #1987: This PR modifies the logic for rendering captchas based on the visibility of the closest form, which aligns with the changes in the main PR that also focus on visibility checks for captchas.
  • Fix pro issue 1961 #2003: This PR addresses issues with reCAPTCHA validation, which is relevant to the changes in the main PR that involve the frmAfterRecaptcha function and its handling of captcha-related logic.

Suggested reviewers

  • Crabcyborg

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 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 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

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 27.33%. Comparing base (4ccad28) to head (7244834).
Report is 48 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #2055   +/-   ##
=========================================
  Coverage     27.32%   27.33%           
- Complexity     8104     8110    +6     
=========================================
  Files           127      127           
  Lines         26918    26930   +12     
=========================================
+ Hits           7356     7361    +5     
- Misses        19562    19569    +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

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

🧹 Outside diff range and nitpick comments (1)
js/formidable.js (1)

1863-1872: LGTM! Captcha rendering logic improved for modal support.

The changes address the issue of Captcha not rendering in Bootstrap modals. The new implementation correctly checks for forms within modals and visible forms, which should resolve the reported problem.

A minor suggestion for improved readability:

Consider extracting the visibility check into a separate function for better readability. For example:

-		let shouldRenderCaptcha;
-		if ( closestForm.closest( '[id^=frm-modal-]' ) ) { // Form is in a modal.
-			shouldRenderCaptcha = true;
-		} else {
-			shouldRenderCaptcha = closestForm.offsetParent !== null; // Form is visible if offsetParent is not null.
-		}
+		const shouldRenderCaptcha = isFormVisibleOrInModal(closestForm);

+ function isFormVisibleOrInModal(form) {
+     return form.closest('[id^=frm-modal-]') || form.offsetParent !== null;
+ }

This change would make the main function more concise and easier to understand at a glance.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d2cba79 and 7244834.

📒 Files selected for processing (1)
  • js/formidable.js (1 hunks)
🧰 Additional context used

@AbdiTolesa
Copy link
Contributor Author

@lauramekaj1 I see an error in the E2E test, I appreciate if you can look into it. Let me know should you have any question or help from me.

@Crabcyborg
Copy link
Contributor

@AbdiTolesa I think the failing e2e tests were because of some update I made the other day.

I just merged the latest version of master into your branch. It should pass now.

@Crabcyborg
Copy link
Contributor

Crabcyborg commented Oct 17, 2024

@AbdiTolesa @lauramekaj1 We went with another way to fix this issue and other similar issues #2058

I'm going to close this one. Don't worry about testing it Laura.

The other fix is verified by Ahmed and myself. I think it's been tested enough.

@Crabcyborg Crabcyborg closed this Oct 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants