Skip to content

Conversation

@arifulhoque7
Copy link
Contributor

@arifulhoque7 arifulhoque7 commented Nov 26, 2025

Fix: Hidden CSS class removes fields from builder

Close issue Close issue, Related PRO PR

  • Filters CSS classes that hide elements (hidden, d-none, invisible, etc.) in form builder only
  • Preserves all CSS classes for frontend rendering
  • Adds visual "Hidden on frontend" badge indicator in builder
  • Adds frontend CSS support for hiding utility classes (hidden, d-none, etc.)
  • Updates both Free and Pro plugins
  • Fixes issue where fields with "hidden" CSS class disappeared in builder and couldn't be edited

Files modified:

  • wp-user-frontend: builder-stage-v4-1/index.js, template.php, frontend-forms.less
  • wp-user-frontend-pro: builder-stage-pro.js

Summary by CodeRabbit

  • New Features
    • Visual "Hidden on frontend" badge added to fields that use hiding CSS classes.
    • New frontend CSS utilities for hiding fields (display none, visibility hidden, screen-reader-only).
    • Builder now sanitizes and validates field CSS class lists and flags hidden-class usage.

✏️ Tip: You can customize this high-level summary in your review settings.

@arifulhoque7 arifulhoque7 requested a review from sapayth November 26, 2025 07:55
@arifulhoque7 arifulhoque7 self-assigned this Nov 26, 2025
@coderabbitai
Copy link

coderabbitai bot commented Nov 26, 2025

Walkthrough

Adds utilities and templates to detect and strip frontend-hiding CSS classes in the form builder, shows a "Hidden on frontend" badge for fields that would be hidden, and introduces frontend CSS/LESS utility classes to hide elements.

Changes

Cohort / File(s) Summary
Builder component methods
admin/form-builder/assets/js/components/builder-stage-v4-1/index.js, assets/js/wpuf-form-builder-components.js
Added hiddenClasses() to list hiding class names, filter_builder_css_classes(cssClasses) to remove hiding-related classes from space-separated strings, and has_hidden_css_class(cssClasses) to detect hiding classes; includes input validation and sanitized outputs.
Builder templates
admin/form-builder/assets/js/components/builder-stage-v4-1/template.php, assets/js-templates/form-components.php
Replaced direct field.css usage with filter_builder_css_classes(field.css) for rendered class lists and added an inline "Hidden on frontend" badge (with SVG) when has_hidden_css_class(field.css) is true.
Frontend styles
assets/css/frontend-forms.css, assets/less/frontend-forms.less
Added utility classes under .wpuf-form to hide elements: .hidden, .d-none, .hide (display:none), .invisible (visibility:hidden), and .sr-only, .visually-hidden (screen-reader hiding).
Field visibility server-side
includes/Admin/Forms/Field_Manager.php
When visibility is 'hidden', prepends a space before the wpuf_hidden_field CSS token when concatenating into the field CSS string.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Pay extra attention to:
    • Edge cases in filter_builder_css_classes and has_hidden_css_class (extra whitespace, duplicates, case sensitivity, partial matches).
    • Template rendering to ensure non-hiding classes and class ordering are preserved.
    • CSS naming collisions with existing utilities or theme styles.

Suggested reviewers

  • sapayth

Poem

🐇 I hopped through classes, sharp and keen,
Snipped hiding names from each machine.
A tiny badge now gleams with pride,
"Hidden on frontend" — no surprise to hide.
✨ Hop, patch, and onward we glean.

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: filtering hidden CSS classes in the form builder while preserving them for frontend rendering.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
assets/js-templates/form-components.php (1)

110-140: Builder now filters hide classes and shows a badge – consider DRY and i18n

  • Using filter_builder_css_classes(field.css) in the :class array is the right way to prevent Tailwind/Bootstrap hide classes from removing the field from the builder preview.
  • The has_hidden_css_class(field.css)-based badge clearly surfaces “Hidden on frontend” state without affecting layout.

Two minor follow-ups:

  • The badge text "Hidden on frontend" and title tooltip are hardcoded English; they should go through translation helpers (e.g. localized string injected into JS) to keep builder UI fully translatable.
  • Column-field inner items in #tmpl-wpuf-form-column_field still use raw field.css (lines 951–956) and won’t benefit from filtering or the badge; for consistency with top-level fields, consider applying filter_builder_css_classes and optionally the same indicator there as well.
admin/form-builder/assets/js/components/builder-stage-v4-1/template.php (1)

17-50: Admin builder template changes are sound but mirror same i18n/consistency concerns

  • Switching to filter_builder_css_classes(field.css) in the main :class binding avoids hidden CSS classes removing fields from the v4.1 builder stage, which directly addresses the reported bug.
  • The has_hidden_css_class(field.css) badge inside the label is a good, non-intrusive affordance to explain why a field won’t appear on the frontend.

Same minor concerns as in the JS template:

  • "Hidden on frontend" and the tooltip string should be localized via translatable strings rather than hardcoded.
  • Inner column-field templates (in the shared templates file) still rely on raw field.css; if users apply hide classes there, those fields may still disappear in the builder. Consider aligning behavior by using the same helper(s) in column contexts.
🧹 Nitpick comments (2)
admin/form-builder/assets/js/components/builder-stage-v4-1/index.js (1)

192-247: Helper methods correctly filter/hint on hide classes; consider sharing the logic

  • filter_builder_css_classes(cssClasses) correctly:
    • Guards non-string/empty input.
    • Normalizes via toLowerCase() before matching.
    • Strips known hide-related classes (hidden, d-none, hide, invisible, opacity-0, sr-only, visually-hidden) while returning the remaining classes as a space-separated string, which works fine in Vue’s :class array binding.
  • has_hidden_css_class(cssClasses) is safe and cheap, and only flags classes that fully hide elements (hidden, d-none, hide, invisible), which matches the “Hidden on frontend” badge semantics.

Two small points:

  • The “forbidden” list here includes opacity-0, sr-only, and visually-hidden, but has_hidden_css_class does not. If you intend the badge to represent “visually not present to typical users”, you may want to include at least opacity-0 and possibly the visually-hidden variants for consistency.
  • The same helpers are implemented verbatim in assets/js/wpuf-form-builder-components.js; extracting them into a shared mixin/utility would avoid divergence over time.

Functionally this is correct and safe for the current PR.

assets/js/wpuf-form-builder-components.js (1)

379-434: Duplicated helper implementations – works now, but centralization would help

This copy of filter_builder_css_classes / has_hidden_css_class matches the implementation in builder-stage-v4-1/index.js, so behavior is consistent between the inline Vue registration and the admin component.

To reduce maintenance risk:

  • Consider moving these helpers into a shared mixin (e.g. wpuf_mixins.builder_css_utils) or a small utility module, and reuse from both places, so any future change to the list of hide classes only needs to be done once.
  • As noted in the other file, you may want to align hiddenClasses with the full set of classes removed by filter_builder_css_classes if the badge should cover all visually-hidden scenarios.

No blocking issues; the logic itself is correct for the current objectives.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 47b6597 and c6a7d6e.

📒 Files selected for processing (6)
  • admin/form-builder/assets/js/components/builder-stage-v4-1/index.js (1 hunks)
  • admin/form-builder/assets/js/components/builder-stage-v4-1/template.php (3 hunks)
  • assets/css/frontend-forms.css (1 hunks)
  • assets/js-templates/form-components.php (3 hunks)
  • assets/js/wpuf-form-builder-components.js (1 hunks)
  • assets/less/frontend-forms.less (1 hunks)
🔇 Additional comments (2)
assets/css/frontend-forms.css (1)

1797-1817: Hide utility classes look correct and well-scoped

The new .wpuf-form .hidden/.d-none/.hide/.invisible/.sr-only/.visually-hidden rules are consistent with common utility semantics, scoped to .wpuf-form, and use !important appropriately so frontend behavior is predictable. No issues from a CSS or UX perspective.

assets/less/frontend-forms.less (1)

2089-2114: LESS source matches compiled CSS and is structured correctly

The LESS block for hide utilities under .wpuf-form { ... } matches the compiled CSS behavior and keeps the utilities neatly scoped. This will compile to the expected selectors and is safe to maintain.

@Rubaiyat-E-Mohammad Rubaiyat-E-Mohammad added the QA Approved This PR is approved by the QA team label Nov 28, 2025
Extended CSS and LESS selectors to support multiple case variations (e.g., .Hidden, .HIDDEN, .D-none, .Hide, .HIDE, .Invisible, .INVISIBLE) for hiding and making fields invisible on the frontend forms. This improves compatibility with different class naming conventions.
Copy link

@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)
assets/less/frontend-forms.less (1)

2089-2122: Clarify the intent behind multiple case variants of each utility class.

The added utilities define three-variants of each hiding class (e.g., .hidden, .Hidden, .HIDDEN for display: none). While CSS is case-sensitive and these are technically distinct selectors, this pattern is non-standard and uncommon in modern web development, which typically uses lowercase class names.

Is this intentional to support existing codebases with mixed casing conventions, or should this be simplified to lowercase variants only (.hidden, .d-none, .hide, etc.)? Having multiple case variants increases maintenance burden without clear benefit.

Please clarify:

  1. Is support for mixed case class names a requirement?
  2. Are there existing forms in the wild using .Hidden or .HIDDEN that must be preserved?
  3. If not, consider simplifying to lowercase-only variants to align with CSS conventions and reduce duplication.

Approved aspects:

  • Screen-reader utilities (.sr-only, .visually-hidden) are correctly implemented per accessibility standards.
  • Scoping within .wpuf-form is appropriate.
  • Use of !important is justified for utility classes.

If mixed casing is not required, simplify to:

- /* CSS utility classes for hiding fields on frontend */
- .wpuf-form {
-     .hidden,
-     .Hidden,
-     .HIDDEN,
-     .d-none,
-     .D-none,
-     .D-None,
-     .hide,
-     .Hide,
-     .HIDE {
+ /* CSS utility classes for hiding fields on frontend */
+ .wpuf-form {
+     .hidden,
+     .d-none,
+     .hide {
          display: none !important;
      }
-
-     .invisible,
-     .Invisible,
-     .INVISIBLE {
+     .invisible {
          visibility: hidden !important;
      }
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c6a7d6e and cd77a81.

📒 Files selected for processing (2)
  • assets/css/frontend-forms.css (1 hunks)
  • assets/less/frontend-forms.less (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • assets/css/frontend-forms.css

@arifulhoque7 arifulhoque7 added the needs: dev review This PR needs review by a developer label Dec 3, 2025
@sapayth sapayth added needs: author reply This PR needs author feedback or code changes and removed needs: dev review This PR needs review by a developer labels Dec 3, 2025
Centralizes the list of hidden CSS classes in a new hiddenClasses() method for the builder-stage-v4-1 Vue component, improving maintainability. Updates Field_Manager.php to add a space before 'wpuf_hidden_field' when setting the CSS class for hidden fields.
Copy link

@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)
includes/Admin/Forms/Field_Manager.php (1)

256-259: Leading space fix is fine; consider normalizing the css value to avoid notices

Adding the leading space makes concatenation safer when css is already populated. However, if $form_field['css'] is unset or non-string, this can still emit notices or produce odd spacing. You could defensively normalize it here:

-            if ( $visibility_selected == 'hidden' ) {
-                $form_field['css'] .= ' wpuf_hidden_field';
-                $show_field        = true;
-            }
+            if ( $visibility_selected == 'hidden' ) {
+                $existing_css       = isset( $form_field['css'] ) ? trim( (string) $form_field['css'] ) : '';
+                $form_field['css']  = $existing_css === '' ? 'wpuf_hidden_field' : $existing_css . ' wpuf_hidden_field';
+                $show_field         = true;
+            }

This keeps the behavior while avoiding undefined-index notices and normalizing whitespace.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cd77a81 and bbfad91.

📒 Files selected for processing (3)
  • admin/form-builder/assets/js/components/builder-stage-v4-1/index.js (1 hunks)
  • assets/js/wpuf-form-builder-components.js (1 hunks)
  • includes/Admin/Forms/Field_Manager.php (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
  • admin/form-builder/assets/js/components/builder-stage-v4-1/index.js
  • assets/js/wpuf-form-builder-components.js

@arifulhoque7 arifulhoque7 added needs: dev review This PR needs review by a developer and removed needs: author reply This PR needs author feedback or code changes labels Dec 4, 2025
@arifulhoque7
Copy link
Contributor Author

Review added @sapayth vai

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs: dev review This PR needs review by a developer QA Approved This PR is approved by the QA team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Need to know where is stored the "...-wpuf-wpuf_forms-date-here.json" file or data

3 participants