Skip to content

Preserve Flask-WTF captcha classes in form macros - #425

Open
2836048681 wants to merge 1 commit into
helloflask:mainfrom
2836048681:fix/408-recaptcha-widget-classes
Open

2836048681 wants to merge 1 commit into
helloflask:mainfrom
2836048681:fix/408-recaptcha-widget-classes

Conversation

@2836048681

Copy link
Copy Markdown

Fixes #408.

Rendering a RecaptchaField currently adds Bootstrap input classes such as form-control. With Flask-WTF 1.3.0, the widget treats this as an explicit class override, replacing the g-recaptcha default or a configured class such as h-captcha. The captcha script then cannot find its target element.

Render captcha widgets without adding Bootstrap input classes in the basic, inline, and horizontal layouts for both Bootstrap 4 and 5. Preserve explicit class/class_ arguments and field render_kw classes, while retaining the existing labels, layout containers, and validation feedback.

Add 48 regression cases covering both Bootstrap versions, all three layouts, render_field, render_form, and render_form_row, default and configured classes, explicit class overrides, additional widget attributes, and validation errors. Update the macro documentation and changelog.

Validation

Python 3.12.3 on Linux:

  • Full suite with requirements/tests.txt unchanged (Flask-WTF 1.2.1, WTForms 3.1.2): 215 passed.
  • Full suite with the same pins and Flask-WTF upgraded to 1.3.0: 215 passed. Python branch coverage: 100%; this coverage figure does not measure Jinja templates.
  • New regressions with Flask-WTF 1.3.0 and WTForms 3.3.2: 48 passed after the fix; the exact same final tests produce 48 failures against the base templates.
  • python -m flake8 flask_bootstrap tests: passed.
  • git diff --cached --check: passed.

Two unrelated existing check failures were investigated:

  • With all latest test dependencies, the full suite has 212 passes and three failures in existing Bootstrap 5 radio-label customization tests (test_class, test_class_inline, and test_class_horizontal). The untouched base commit has the exact same three failures and 164 passes, before adding the 48 new cases. Both runs use Flask-WTF 1.3.0 and WTForms 3.3.2.
  • The strict Sphinx build completes HTML generation but exits with one warning for the existing undefined input_customization label. Building the complete base-commit source archive reproduces the same single warning. No documentation warning was introduced by this change.

Rendering tests use a dummy public key and do not contact a captcha service or require private credentials. Other Python versions and operating systems were not tested locally.

This branch has not been deployed

No deployments
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.

Consider adding special treatment for Recaptcha field used by Flask-WTF

2 participants