-
Notifications
You must be signed in to change notification settings - Fork 91
gw-quantity-as-decimal.php
: Fixed an issue with Calculation Product field not editable with decimal values.
#720
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
base: master
Are you sure you want to change the base?
Conversation
… field not editable with decimal values.
… field not editable with decimal values.
WalkthroughThe changes update the logic in the Changes
Sequence Diagram(s)sequenceDiagram
participant GF as Gravity Forms Plugin
participant QD as GW_Quantity_Decimal
GF->>QD: Call init()
alt Gravity Forms version >= 2.8 or HTML5 enabled
QD->>Filters: Register render and modify input filters
else Not met
QD->>GF: Return early (skip filters)
end
Note over QD: Later in processing, when handling a quantity field input
GF->>QD: Process input field
QD->>QD: Call fix_content() to modify input HTML (adding step="any" if needed)
📜 Recent review detailsConfiguration used: CodeRabbit UI 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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)
gravity-forms/gw-quantity-as-decimal.php (1)
96-114
: Good implementation that targets only necessary fieldsThe
fix_content
function effectively addresses the original issue by:
- Only targeting inputs with the
ginput_quantity
class- Only modifying fields that have decimal values
- Only adding the
step="any"
attribute when it's not already presentThis implementation satisfies the previous review request to "make sure it's only targeting the desired fields."
One minor suggestion - consider adding a check for the
min
attribute in the HTML to make the targeting even more specific, since that's what causes the original issue according to the PR objectives:if ( preg_match('/\bvalue=[\'"]([\d]+\.[\d]+)[\'"]/i', $inputTag, $valueMatch ) ) { - if ( ! preg_match('/\bstep=[\'"]any[\'"]/i', $inputTag ) ) { + if ( ! preg_match('/\bstep=[\'"]any[\'"]/i', $inputTag ) && preg_match('/\bmin=[\'"]0[\'"]/i', $inputTag) ) { $inputTag = preg_replace( '/<input/i', '<input step="any"', $inputTag, 1 ); } }
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
gravity-forms/gw-quantity-as-decimal.php
(2 hunks)
🔇 Additional comments (3)
gravity-forms/gw-quantity-as-decimal.php (3)
46-49
: Good approach for version compatibilityAdding this conditional check ensures backward compatibility while fixing the issue for newer Gravity Forms versions or when HTML5 is manually enabled. Early return pattern is appropriate here.
51-55
: Proper organization of filter hooksMoving these filter hooks inside the conditional block ensures they're only added when needed (GF 2.8+ or HTML5 enabled). The comments clearly explain the reasoning behind the conditions.
56-56
: Well-placed content filterAdding the
gform_field_content
filter to handle the fix is appropriate, as it will process the field after it's been rendered but before it's displayed to the user.
…ield` Docstrings generation was requested by @saifsultanc. * #720 (comment) The following files were modified: * `gravity-forms/gw-quantity-as-decimal.php`
Note Generated docstrings for this pull request at #1045 |
… field not editable with decimal values.
Context
⛑️ Ticket(s): https://secure.helpscout.net/conversation/2386150351/55864?folderId=3808239
Summary
https://github.com/gravitywiz/snippet-library/blob/master/gravity-forms/gw-quantity-as-decimal.php
The snippet doesn't work when editing the quantity of a calculated product field on the backend. This happens when the "Output HTML5" setting is enabled on Gravity Forms. On the Calculation field, Gravity Forms runs this logic:
$qty_min_attr = GFFormsModel::is_html5_enabled() ? "min='0'" : '';
This adds the
"min='0'"
to the input field (For example,<input type="number" name="input_3.3" value="5.2" id="ginput_quantity_305_3" class="ginput_quantity" size="10" min="0">
. This field would not be editable with decimal values now.To fix this, we can add the
step
attribute