Skip to content

Work on adding show options to code list pop up#1379

Open
Crabcyborg wants to merge 32 commits into
masterfrom
work_on_adding_show_options_to_code_list_popup
Open

Work on adding show options to code list pop up#1379
Crabcyborg wants to merge 32 commits into
masterfrom
work_on_adding_show_options_to_code_list_popup

Conversation

@Crabcyborg
Copy link
Copy Markdown
Contributor

@Crabcyborg Crabcyborg commented Nov 17, 2023

Related update https://github.com/Strategy11/formidable-pro/pull/4573 (merged)
Requires: https://github.com/Strategy11/formidable-pro/pull/5394

TODO

  • Add show=label options for fields with options as well.
image

Test procedure

  1. Create a form and add a Text field, Name field and an option field like Dropdown field.
  2. For the Dropdown field, change one of the labels to a number, like 10 for example.
  3. For the option fields select 'Use separate values' option.
  4. Go to the Text field options and under Advanced > Default Value click on the Calculation tab.
  5. Click on the three dots to trigger the field shortcodes popup and Select 'Text' tab for the calculation.
  6. Confirm that the name field now has three more shortcode options that allows inserting a name part. Ex. show=first
  7. Insert one of the new show shortcodes in the calculation.
  8. Save and Preview the form.
  9. Confirm that everything works as expected.
  10. Turn back to the form builder and check that an additional show=label option is available for the Dropdown field.
  11. Now, change the calculation of the text field to from 'Text' to 'Math' using the tab and insert the show=label shortcode into the calculation and build a number calculation from that adding more operands.
  12. Save and Preview the form.
  13. Confirm that the number calculation works as expected when a number label is selected for the Dropdown field.
image

@codecov
Copy link
Copy Markdown

codecov Bot commented Nov 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (cef6149) 29.26% compared to head (c707b68) 29.27%.

Additional details and impacted files
@@            Coverage Diff            @@
##             master    #1379   +/-   ##
=========================================
  Coverage     29.26%   29.27%           
  Complexity     7263     7263           
=========================================
  Files           105      105           
  Lines         23937    23937           
=========================================
+ Hits           7006     7007    +1     
+ Misses        16931    16930    -1     

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

@Crabcyborg
Copy link
Copy Markdown
Contributor Author

@AbdiTolesa I was working on adding support for show=first/show=last to the shortcode pop up for name fields to make it easier to insert these special options.

Do you think you'd be able to try taking this over and wrapping it up? I was hoping to also include show="label" for the fields with options that have "Use separate values" enabled as well.

Thank you!

@AbdiTolesa AbdiTolesa marked this pull request as ready for review September 25, 2024 06:11
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 25, 2024

Walkthrough

Added three helper functions to centralize creation and insertion of calculation-field list items and to conditionally add label and name-part shortcodes when populating the calculation-field popup in the form builder UI.

Changes

Cohort / File(s) Change Summary
Calc helpers & admin integration
js/formidable_admin.js, js/src/admin/admin.js
Added addCalcFieldLiToList(list, fieldId, code, label, fieldType), shouldShowFieldLabelShortcode(fieldType, fieldId), and maybeAddNamePartShortcodes(field, fieldId, list). Replaced manual calc-field list item construction with these helpers; conditionally include [fieldId show=label] and show=first/middle/last shortcodes for name fields when appropriate.
CSS adjustments
css/admin/frm-settings-components.css, css/frm_testing_mode.css
Reintroduced a large CSS block in frm-settings-components.css (appears duplicated). Modified comment delimiter placement in frm_testing_mode.css around a Bootstrap comment block, which may affect CSS parsing.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant UI as Calc Field Popup UI
  participant Admin as js/src/admin/admin.js
  participant Helpers as js/formidable_admin.js

  UI->>Admin: populateCalcFieldList(fields)
  Admin->>Helpers: evaluate each field
  alt eligible field
    Helpers->>Helpers: addCalcFieldLiToList(list, fieldId, code, label, fieldType)
    opt show label shortcode
      Helpers->>Helpers: add "[fieldId show=label]"
    end
    opt name field
      Helpers->>Helpers: maybeAddNamePartShortcodes(field, fieldId, list)
    end
    Helpers-->>Admin: appended items
  else skipped
    Helpers-->>Admin: skip field
  end
  Admin-->>UI: render populated list
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–30 minutes

  • Review focus:
    • Inclusion/exclusion rules for which field types get added (js/formidable_admin.js).
    • Correct invocation, parameters, and side effects of new helpers in js/src/admin/admin.js.
    • Edge cases for name field part shortcodes and label-shortcode visibility logic.
    • CSS comment change in css/frm_testing_mode.css that may break parsing.

Suggested reviewers

  • truongwp

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Work on adding show options to code list pop up' accurately describes the main change: adding show options (show=label, show=first, show=middle, show=last) to the field shortcodes popup for calculations.
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing the feature implementation of show options for Name and option fields, including test procedures and relevant screenshots.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch work_on_adding_show_options_to_code_list_popup

📜 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 9f75a6c and 1bb6eb7.

📒 Files selected for processing (1)
  • js/src/admin/admin.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • js/src/admin/admin.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: Cypress

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
Copy Markdown
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: 2

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between aa982e7 and d0e5cc0.

Files selected for processing (1)
  • js/formidable_admin.js (1 hunks)
🔇 Additional comments not posted (2)
js/formidable_admin.js (2)

2905-2907: Ensure browser compatibility

The shouldShowFieldLabelShortcode function uses optional chaining (?.) and includes, which are relatively modern JavaScript features.

Verify that the browsers supported by the Formidable Forms plugin are compatible with these features, or consider providing polyfills or fallback mechanisms for older browsers if necessary.

#!/bin/bash

# Check browser compatibility for optional chaining and includes
ast-grep --lang js --pattern $'
  $$$
  (_) ?. (_)
  $$$
'

ast-grep --lang js --pattern $'
  $$$
  (_).includes(_)  
  $$$
'

2895-2907: Verify compatibility with existing functionality

The new shouldShowFieldLabelShortcode function introduces new logic for determining whether to show the field label shortcode based on the field type and "Use separate values" checkbox state.

Ensure this change is thoroughly tested and does not introduce any regressions or compatibility issues with existing functionality related to calculation fields.

Comment thread js/formidable_admin.js Outdated
Copy link
Copy Markdown
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: 4

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

Line range hint 1-3070: Good use of module pattern, but consider breaking it down

The frmAdminBuildJS function implements the module pattern, which is a good practice for encapsulation and organizing code. It creates a closure that contains private functions and variables, while returning an object with public methods and properties. This approach helps in maintaining a clean global namespace and controlling access to internal functionality.

However, the function is quite large and contains many nested functions and variables. Consider breaking this down into smaller, more focused modules or sub-modules. This could improve readability, maintainability, and make it easier to test individual components.

Here's a high-level suggestion for refactoring:

  1. Identify logical groupings of functionality (e.g., form building, settings, export/import).
  2. Create separate modules for each group.
  3. Use ES6 modules or a similar system to manage dependencies between these modules.
  4. Maintain a main module that initializes and coordinates these sub-modules.

This approach would make the code more modular and easier to maintain in the long run.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between d6b8a36 and cdafa45.

📒 Files selected for processing (1)
  • js/formidable_admin.js (1 hunks)

Comment thread js/formidable_admin.js Outdated
Comment thread js/formidable_admin.js Outdated
Comment thread js/formidable_admin.js Outdated
@AbdiTolesa AbdiTolesa requested a review from truongwp October 1, 2024 06:05
Comment thread js/formidable_admin.js Outdated
Comment thread js/formidable_admin.js Outdated
@AbdiTolesa AbdiTolesa requested a review from truongwp October 3, 2024 07:04
Copy link
Copy Markdown
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: 1

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Files that changed from the base of the PR and between 8d1c7f5 and f80ffde.

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

[error] 2867-2868: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

🔇 Additional comments (2)
js/formidable_admin.js (2)

2893-2912: Looks good! The new function adds useful functionality.

The maybeAddNamePartShortcodes function is well-structured and adds the ability to insert [nameFieldId show=first], [nameFieldId show=middle] and [nameFieldId show=last] shortcodes to the calculation popup for name fields.

It uses Object.entries and forEach to efficiently loop through the name parts and their labels, and calls addCalcFieldLiToList to add the shortcode <li> elements.

The function is also properly scoped to only run for 'name' field types.


2937-2959: Looks good! The new function improves code modularity.

The new addCalcFieldLiToList function encapsulates the logic for constructing and appending the field shortcode <li> elements to the calculation popup.

It takes the necessary parameters and uses them to build the <a> and <li> elements with the appropriate classes and attributes.

Extracting this logic into a separate function improves code modularity and reusability. The function is also well-documented with JSDoc comments explaining the parameters and return value.

Comment thread js/formidable_admin.js Outdated
Copy link
Copy Markdown
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 (3)
js/formidable_admin.js (3)

2862-2884: LGTM! Consider extracting option validation logic

The code for handling excluded options and field validation looks good. For improved readability, consider extracting the option validation logic into a separate helper function.

function validateFieldOption(field, excludedOpts) {
  return excludedOpts.some(opt => {
    const inputs = document.getElementsByName(getFieldOptionInputName(opt, field.fieldId));
    return inputs.length && jQuery(inputs[0]).val();
  });
}
🧰 Tools
🪛 Biome (1.9.4)

[error] 2872-2873: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)


2933-2964: Consider adding parameter type documentation

The addCalcFieldLiToList function is well-implemented but could benefit from more detailed parameter documentation. Consider adding TypeScript-style JSDoc parameter types:

/**
 * Adds a calculation field list item
 * @param {HTMLElement} list - The list element to append to
 * @param {string} fieldId - The field ID
 * @param {string} code - The field code
 * @param {string} label - The field label
 * @param {string} fieldType - The field type
 */
function addCalcFieldLiToList(list, fieldId, code, label, fieldType) {

2872-2873: Use optional chaining for safer array access

Consider using optional chaining to make the array access safer:

if ( fieldOptions?.length < 2 ) {
  return;
}

This change would prevent potential errors if fieldOptions is undefined.

🧰 Tools
🪛 Biome (1.9.4)

[error] 2872-2873: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between b528490 and 3ca1927.

📒 Files selected for processing (1)
  • js/formidable_admin.js (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
js/formidable_admin.js

[error] 2872-2873: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Run PHP Syntax inspection (8.3)
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: Cypress
🔇 Additional comments (1)
js/formidable_admin.js (1)

2887-2931: Well-structured name field handling with good documentation

The implementation of name part shortcodes is clean and well-documented. Good use of JSDoc comments and modern JavaScript features.

@Crabcyborg Crabcyborg modified the milestones: 6.17, 6.17.1 Jan 14, 2025
@Crabcyborg Crabcyborg modified the milestones: 6.18, 6.19 Feb 10, 2025
@Crabcyborg Crabcyborg removed this from the 6.19 milestone Feb 14, 2025
Copy link
Copy Markdown
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: 1

🔭 Outside diff range comments (1)
js/formidable_admin.js (1)

2967-2987: 🛠️ Refactor suggestion

Add error handling for JSON parse

The getExcludeArray function parses JSON without error handling.

Add try/catch block around JSON.parse:

- const exclude = JSON.parse(box.getElementsByClassName('frm_code_list')[0].getAttribute('data-exclude'));
+ let exclude = [];
+ try {
+   const excludeAttr = box.getElementsByClassName('frm_code_list')[0].getAttribute('data-exclude');
+   exclude = excludeAttr ? JSON.parse(excludeAttr) : [];
+ } catch (e) {
+   console.error('Error parsing exclude data:', e);
+ }
♻️ Duplicate comments (1)
js/formidable_admin.js (1)

2929-2931: 🛠️ Refactor suggestion

Fix potential undefined return in shouldShowFieldLabelShortcode

The optional chaining operator could return undefined instead of a boolean.

Add an explicit boolean conversion:

- return [ 'radio', 'checkbox', 'dropdown' ].includes( fieldType ) && document.getElementById( `separate_value_${fieldId}` )?.checked;
+ return [ 'radio', 'checkbox', 'dropdown' ].includes( fieldType ) && !! document.getElementById( `separate_value_${fieldId}` )?.checked;
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3ca1927 and 7da58a6.

📒 Files selected for processing (1)
  • js/formidable_admin.js (1 hunks)
🧰 Additional context used
🪛 Biome (1.9.4)
js/formidable_admin.js

[error] 2872-2873: Change to an optional chain.

Unsafe fix: Change to an optional chain.

(lint/complexity/useOptionalChain)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cypress
🔇 Additional comments (3)
js/formidable_admin.js (3)

2877-2884: LGTM: Proper field list handling

The field list generation and shortcode support check is implemented correctly. The code properly checks for the data-supportsShowShortcodes attribute before adding additional shortcode options.


2898-2917: LGTM: Well-structured name field shortcode handling

The maybeAddNamePartShortcodes function is well-implemented with:

  • Clear type checking
  • Proper field ID validation
  • Localized labels using __()
  • Clean iteration over name parts

2942-2965: LGTM: Well-structured list item creation

The addCalcFieldLiToList function follows best practices:

  • Uses template literals for string interpolation
  • Properly escapes HTML content
  • Uses semantic HTML elements
  • Includes proper data attributes

Comment thread js/formidable_admin.js Outdated
@Crabcyborg
Copy link
Copy Markdown
Contributor Author

@AbdiTolesa Sorry I let this PR get so old.

We've updated the admin JS now so it's in a different admin.js file, and this file that's being changed is minified now.

So we'll need to move these changes into the new file.

Could you help with that?

Thank you!

@AbdiTolesa
Copy link
Copy Markdown
Contributor

So we'll need to move these changes into the new file.

Could you help with that?

@Crabcyborg I have moved the changes to the source js files both in this PR and https://github.com/Strategy11/formidable-pro/pull/5394

Copy link
Copy Markdown
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: 1

🧹 Nitpick comments (4)
js/src/admin/admin.js (4)

3050-3065: Feature flag truthiness can misfire; make it explicitly boolean

dataset.supportsShowShortcodes is a string and any non-empty value (including "0") is truthy. Prefer a presence or explicit boolean parse to avoid accidental enabling.

-const supportsShowShortcodes = document.getElementById( 'new_fields' ).dataset.supportsShowShortcodes;
+const newFieldsEl = document.getElementById( 'new_fields' );
+const supportsShowShortcodes = newFieldsEl?.hasAttribute( 'data-supports-show-shortcodes' ) &&
+  (newFieldsEl.dataset.supportsShowShortcodes === '' ||
+   /^(1|true|yes)$/i.test( newFieldsEl.dataset.supportsShowShortcodes ));

3113-3145: Minor UI polish: add spacing and accessible label to shortcode items

Currently the label text is concatenated directly after “[code]” with no space, and the link lacks an accessible label. Add a space node and aria-label to improve readability/AT support.

 function addCalcFieldLiToList( list, fieldId, code, label, fieldType ) {
   const anchor = a( {
     className: 'frm_insert_code',
     children: [
       span( {
         text: '[' + code + ']'
       } ),
-      document.createTextNode( label )
+      document.createTextNode( ' ' ),
+      document.createTextNode( label )
     ],
     data: {
       code
-    }
+    },
+    ariaLabel: label + ' shortcode ' + '[' + code + ']'
   } );

3068-3097: Scope OK; consider reflecting actual Name subparts to avoid dangling options

Nice addition. If practical, hide parts not enabled in the Name field’s current layout (e.g., no Middle) to reduce confusion in the popup.

Please confirm if the Name layout setting is available in DOM (eg, a per-field dropdown). If so, I can wire a small check to only add present parts.


3068-3097: Doc nit: replace “@SInCE x.x” with the release version

Update the JSDoc @since tags to the actual version used in this release.

Also applies to: 3099-3112, 3113-3145

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7da58a6 and 20367ef.

📒 Files selected for processing (1)
  • js/src/admin/admin.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
js/src/admin/admin.js (1)
js/admin/dom.js (5)
  • __ (4-4)
  • label (366-372)
  • label (740-740)
  • anchor (710-710)
  • a (27-33)

Comment thread js/src/admin/admin.js
Comment thread js/src/admin/admin.js Outdated
Copy link
Copy Markdown
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: 1

♻️ Duplicate comments (1)
js/src/admin/admin.js (1)

3096-3109: Dropdowns won’t show “label” shortcode — include 'select' in type check

The field type array omits 'select' (used for Dropdowns elsewhere), so [fieldId show=label] never appears for Dropdown fields.

Apply:

-function shouldShowFieldLabelShortcode( fieldType, fieldId ) {
-  return [ 'radio', 'checkbox', 'dropdown' ].includes( fieldType ) && !! document.getElementById( `separate_value_${ fieldId }` )?.checked;
-}
+function shouldShowFieldLabelShortcode( fieldType, fieldId ) {
+  // Support actual Dropdown type ('select'); keep 'dropdown' for safety if referenced elsewhere.
+  return [ 'radio', 'checkbox', 'select', 'dropdown' ].includes( fieldType ) &&
+    !! document.getElementById( `separate_value_${ fieldId }` )?.checked;
+}

Please also confirm this UI‑side check aligns with Pro behavior (comment noted that Pro needs no changes). [Based on past review comments]

🧹 Nitpick comments (3)
js/src/admin/admin.js (3)

3110-3141: Minor UI nit: add spacing between “[code]” and label

Currently renders as “[123]My Field”. Add a leading space to the label text node.

-        document.createTextNode( label )
+        document.createTextNode( ' ' + label )

3064-3095: Name parts: consider hiding “Middle” when not enabled on the field

You always add first/middle/last. If the Name field is configured without a middle part, showing “(Middle)” may confuse. Optional: gate on the field’s current layout/settings (if available) before adding that shortcode. I can draft a DOM check if you confirm where the layout is stored.


3064-3141: Replace @SInCE x.x placeholders

Docblocks use “@SInCE x.x”. Replace with the actual next version tag used in this repo to keep docs accurate.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 20367ef and cb38709.

📒 Files selected for processing (1)
  • js/src/admin/admin.js (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
js/src/admin/admin.js (1)
js/admin/dom.js (5)
  • __ (4-4)
  • label (366-372)
  • label (740-740)
  • anchor (710-710)
  • a (27-33)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: PHP 8 tests in WP trunk
  • GitHub Check: PHP 7.4 tests in WP trunk
  • GitHub Check: Cypress
  • GitHub Check: Run PHP Syntax inspection (8.3)

Comment thread js/src/admin/admin.js
- Added maybeAddAddressPartShortcodes function to support Address field part shortcodes (line1, line2, city, state, zip, country)
- Added function call in field population loop to display Address field parts in calculation popup
- Similar pattern to Name field implementation

Resolves #5825
- Use template literals instead of string concatenation
- Extract addressParts as const variable for better readability
- Add descriptive JSDoc parameter documentation
- Refine function description to be more professional and direct
- Cleaner forEach syntax with consistent formatting
…hortcodes

- Remove hyphens from JSDoc parameter descriptions for consistency with project style
- Align parameter documentation format with standard JSDoc conventions
shervElmi and others added 2 commits December 9, 2025 21:17
- Added wp.hooks.doAction('frm_add_calc_field_shortcodes') hook
- Removed maybeAddAddressPartShortcodes() function (Address fields are Pro-only)
- Allows Pro and other extensions to add custom field part shortcodes
- Well-documented hook with JSDoc for extension developers
…ptions

Add Address field part shortcodes to calculation popup
Copy link
Copy Markdown
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

♻️ Duplicate comments (2)
js/src/admin/admin.js (2)

3056-3074: Localize the “(Label)” suffix in label shortcode entry and avoid hard‑coded English

The UI label for the [fieldId show=label] entry is built as fields[ i ].fieldName + ' (Label)', which is not translatable. This should use the existing i18n helpers so the suffix is localized and consistent with the rest of the admin UI.

A minimal change inline with existing patterns:

- if ( shouldShowFieldLabelShortcode( fields[ i ].fieldType, fields[ i ].fieldId ) ) {
-   addCalcFieldLiToList( list, fieldId, fields[ i ].fieldId + ' show=label', fields[ i ].fieldName + ' (Label)', fields[ i ].fieldType );
- }
+ if ( shouldShowFieldLabelShortcode( fields[ i ].fieldType, fields[ i ].fieldId ) ) {
+   addCalcFieldLiToList(
+     list,
+     fieldId,
+     fields[ i ].fieldId + ' show=label',
+     sprintf( __( '%s (Label)', 'formidable' ), fields[ i ].fieldName ),
+     fields[ i ].fieldType
+   );
+ }

This keeps the UX the same while making the suffix properly translatable.


3119-3121: Dropdowns won’t ever show [fieldId show=label] — type check is missing 'select'

shouldShowFieldLabelShortcode only allows ['radio', 'checkbox', 'dropdown']. In this codebase Dropdown fields actually use the type string 'select' elsewhere, so real Dropdown fields will never satisfy this check and their show=label entries won’t appear in the popup.

Recommend broadening the type list so Dropdowns are correctly supported:

-function shouldShowFieldLabelShortcode( fieldType, fieldId ) {
-  return [ 'radio', 'checkbox', 'dropdown' ].includes( fieldType ) && !! document.getElementById( `separate_value_${ fieldId }` )?.checked;
-}
+function shouldShowFieldLabelShortcode( fieldType, fieldId ) {
+  // Support actual Dropdown type ('select'); keep 'dropdown' in case it exists elsewhere.
+  return [ 'radio', 'checkbox', 'select', 'dropdown' ].includes( fieldType ) &&
+    !! document.getElementById( `separate_value_${ fieldId }` )?.checked;
+}

This aligns the new feature with existing field-type conventions and ensures show=label is available for Dropdowns when “Use separate values” is enabled.

🧹 Nitpick comments (3)
js/src/admin/admin.js (3)

3077-3107: Name-part shortcodes helper looks good; consider aligning with actual name layout (optional)

maybeAddNamePartShortcodes cleanly adds [nameFieldId show=first|middle|last] entries and correctly uses __() for the sublabels, which matches the PR intent.

If you want to tighten UX later, you could read the Name field’s configured layout (eg, which parts are enabled) and skip generating entries for disabled parts so you don’t offer shortcodes like show=middle when no middle-name subfield will ever render. That would avoid confusing, non-functional options in the popup.


3132-3155: Helper for calc-field list items is solid; consider minor accessibility polish

addCalcFieldLiToList centralizes the markup for calc-field entries and correctly stores the raw shortcode in a data-code attribute, which makes the new hook API easier to use and keeps the DOM structure consistent.

Two small optional tweaks you might consider:

  • Add an href="#" (or role="button" and tabindex="0") to the <a> so it’s keyboard-focusable and announced as interactive even if JS fails.
  • If you expect add-ons to call this with non-string fieldId, you might document/normalize it to a string to avoid surprising class names.

No blockers here; helper is otherwise well-factored.


3062-3074: Replace @since x.x placeholders before release

The new frm_add_calc_field_shortcodes hook and helper docblocks still use @since x.x. Before tagging a release, these should be updated to the actual version number so downstream developers have accurate version metadata in the public JS API.

Purely documentation/i18n hygiene; no functional impact.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between cb38709 and 6b72e5c.

📒 Files selected for processing (1)
  • js/src/admin/admin.js (1 hunks)

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.

5 participants