Skip to content

gpadvs-caret-position.js: Added snippet to include Caret Position with GPAS. #1125

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

saifsultanc
Copy link
Contributor

Context

⛑️ Ticket(s): https://secure.helpscout.net/conversation/2977271468/85589

Summary

A snippet to include the Caret Position plugin for Advanced Select.

How the update works:
https://www.loom.com/share/207872ed42ec4e84be6edc514be01e43

Copy link

coderabbitai bot commented Jun 25, 2025

Walkthrough

A new JavaScript snippet was added to enable caret position and input autogrow support for multiselect fields in Gravity Perks Advanced Select. It hooks into the gpadvs_settings filter, detects multiselect field types, and activates the Tom Select caret_position and input_autogrow plugins by modifying the field's settings during initialization.

Changes

File(s) Change Summary
gp-advanced-select/gpadvs-caret-position.js Added a script that registers a filter to enable the Tom Select caret position and input autogrow plugins for multiselect fields.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant Gravity Forms
    participant gpadvs-caret-position.js
    participant Tom Select

    User->>Gravity Forms: Loads Advanced Select field (multiselect)
    Gravity Forms->>gpadvs-caret-position.js: Triggers gpadvs_settings filter
    gpadvs-caret-position.js->>Gravity Forms: Modifies settings (enables caret_position and input_autogrow plugins)
    Gravity Forms->>Tom Select: Initializes with updated settings
    Tom Select-->>User: Provides multiselect with caret position and input autogrow support
Loading

Possibly related PRs


📜 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 3c7d44d and 7664a49.

📒 Files selected for processing (1)
  • gp-advanced-select/gpadvs-caret-position.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • gp-advanced-select/gpadvs-caret-position.js
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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 generate sequence diagram to generate a sequence diagram of the changes in 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

github-actions bot commented Jun 25, 2025

Warnings
⚠️ When ready, don't forget to request reviews on this pull request from your fellow wizards.

Generated by 🚫 dangerJS against 7664a49

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: 1

🧹 Nitpick comments (1)
gp-advanced-select/gpadvs-caret-position.js (1)

17-17: Consider documenting the unused parameter.

The selectNamespace parameter is defined but not used in the implementation. If it's required by the filter API, consider adding a comment to clarify its purpose or potential future use.

-    function(settings, gpadvsInstance, selectNamespace) {
+    function(settings, gpadvsInstance, selectNamespace /* unused - reserved for future use */) {
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ad33967 and 3c7d44d.

📒 Files selected for processing (1)
  • gp-advanced-select/gpadvs-caret-position.js (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Danger JS
🔇 Additional comments (2)
gp-advanced-select/gpadvs-caret-position.js (2)

1-14: Excellent documentation and clear instructions.

The header provides comprehensive information about the snippet's purpose, references, and installation instructions. Well-formatted and professional.


15-29: Well-implemented integration with proper scoping.

The implementation correctly uses the Gravity Forms filter system and appropriately limits the functionality to multiselect fields. The code structure is clean and follows JavaScript best practices.

Comment on lines 21 to 25
if (gpadvsInstance.fieldType === 'multiselect') {
settings.plugins.caret_position = {
title: 'Caret Position',
};
}
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Add defensive programming to prevent potential runtime errors.

The code assumes settings.plugins exists, but if it's undefined, assigning to settings.plugins.caret_position will throw an error.

Apply this diff to add proper defensive checks:

        if (gpadvsInstance.fieldType === 'multiselect') {
+           if (!settings.plugins) {
+               settings.plugins = {};
+           }
            settings.plugins.caret_position = {
                title: 'Caret Position',
            };
        }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (gpadvsInstance.fieldType === 'multiselect') {
settings.plugins.caret_position = {
title: 'Caret Position',
};
}
if (gpadvsInstance.fieldType === 'multiselect') {
if (!settings.plugins) {
settings.plugins = {};
}
settings.plugins.caret_position = {
title: 'Caret Position',
};
}
🤖 Prompt for AI Agents
In gp-advanced-select/gpadvs-caret-position.js around lines 21 to 25, the code
assigns to settings.plugins.caret_position without verifying that
settings.plugins is defined, which can cause runtime errors. Add a defensive
check to ensure settings.plugins exists before assigning caret_position,
initializing settings.plugins as an empty object if it is undefined.

@saifsultanc saifsultanc changed the title gpadvs-caret-position.js: Added snippet toinclude Caret Position with GPAS. gpadvs-caret-position.js: Added snippet to include Caret Position with GPAS. Jun 25, 2025
@spivurno
Copy link
Contributor

@saifsultanc Are you seeing how it forces the one of the options to the far right in your video? I think it might be due to styles we've applied on the search input inside the ADVS-enabled field.

@saifsultanc
Copy link
Contributor Author

@saifsultanc Are you seeing how it forces the one of the options to the far right in your video? I think it might be due to styles we've applied on the search input inside the ADVS-enabled field.

Actually it happens without the styles we have applied, so just the base 'tom-select.css' in play. See :
https://www.loom.com/share/d03b536e8ccf4c7ab2268ea62b3f17f0

@spivurno
Copy link
Contributor

@saifsultanc Right, but do you see how it doesn't happen in their own demo?

@saifsultanc
Copy link
Contributor Author

@saifsultanc Right, but do you see how it doesn't happen in their own demo?

@spivurno Shoot! I didn't realize they had a demo on there.

I see it does happen for them :https://www.loom.com/share/0feb1e991c5342e4b8fa86544922e241

However, it's just a small space on their demo and on our end it's definitely uglier than that - more like a tabbed space. Let me look into this!

@saifsultanc
Copy link
Contributor Author

@spivurno This is fixed, this is how it looks now: https://www.loom.com/share/045105c2182e4f96950c53b27c3ed48b

They have the input_autogrow plugin, and that was also implemented with caret_position on their example. We just needed that.

@spivurno
Copy link
Contributor

@saifsultanc Perfect. 👌

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

Successfully merging this pull request may close these issues.

2 participants