From 0d1c480fd25fc7744c65714a98b1035fec7d87da Mon Sep 17 00:00:00 2001 From: saifsultanc Date: Thu, 12 Oct 2023 20:09:22 +0530 Subject: [PATCH 1/3] `gw-quantity-as-decimal.php`: Fixed an issue with Calculation Product field not editable with decimal values. --- gravity-forms/gw-quantity-as-decimal.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/gravity-forms/gw-quantity-as-decimal.php b/gravity-forms/gw-quantity-as-decimal.php index 9daada007..9f4a41f90 100644 --- a/gravity-forms/gw-quantity-as-decimal.php +++ b/gravity-forms/gw-quantity-as-decimal.php @@ -48,6 +48,7 @@ function init() { add_filter( 'gform_field_input', array( $this, 'modify_quantity_input_tag' ), 10, 5 ); } + add_filter( 'gform_field_content', array( $this, 'fix_content' ), 10, 5 ); } function allow_quantity_float( $result, $value, $form, $field ) { @@ -87,6 +88,11 @@ function modify_quantity_input_tag( $markup, $field, $value, $lead_id, $form_id return $markup; } + function fix_content( $content, $field, $value, $lead_id, $form_id ) { + // ensure the quantity min attribute. + return preg_replace( '/\smin=["\']0["\']/', 'min="0" step="any"', $content ); + } + function get_field_input( $field, $value, $form ) { remove_filter( 'gform_field_input', array( $this, 'modify_quantity_input_tag' ), 10, 5 ); From 4f83701046bd0d85bf295e532a6970825f6bfa28 Mon Sep 17 00:00:00 2001 From: Saif Sultan Date: Mon, 10 Mar 2025 14:47:08 +0530 Subject: [PATCH 2/3] `gw-quantity-as-decimal.php`: Fixed an issue with Calculation Product field not editable with decimal values. --- gravity-forms/gw-quantity-as-decimal.php | 30 ++++++++++++++++++++---- 1 file changed, 25 insertions(+), 5 deletions(-) diff --git a/gravity-forms/gw-quantity-as-decimal.php b/gravity-forms/gw-quantity-as-decimal.php index 9f4a41f90..b2ad6add5 100644 --- a/gravity-forms/gw-quantity-as-decimal.php +++ b/gravity-forms/gw-quantity-as-decimal.php @@ -43,11 +43,16 @@ function init() { add_filter( 'gform_field_validation_' . $this->form_id, array( $this, 'allow_quantity_float' ), 10, 4 ); } - if ( GFFormsModel::is_html5_enabled() ) { - add_filter( 'gform_pre_render', array( $this, 'stash_current_form' ) ); - add_filter( 'gform_field_input', array( $this, 'modify_quantity_input_tag' ), 10, 5 ); + // For GF versions before 2.8 and HTML5 disabled, ignore the rest. + if ( version_compare( GFCommon::$version, '2.8', '<' ) && ! GFFormsModel::is_html5_enabled() ) { + return; } + // For GF versions 2.8 and beyond, HTML5 is enabled by default. + // Also for GF versions prior to 2.8 having HTML5 manually enabled. + add_filter( 'gform_pre_render', array( $this, 'stash_current_form' ) ); + add_filter( 'gform_field_input', array( $this, 'modify_quantity_input_tag' ), 10, 5 ); + add_filter( 'gform_field_content', array( $this, 'fix_content' ), 10, 5 ); } @@ -89,8 +94,23 @@ function modify_quantity_input_tag( $markup, $field, $value, $lead_id, $form_id } function fix_content( $content, $field, $value, $lead_id, $form_id ) { - // ensure the quantity min attribute. - return preg_replace( '/\smin=["\']0["\']/', 'min="0" step="any"', $content ); + // ensure the step is 'any' for any fields that have a decimal value. + return preg_replace_callback( + '/]*class=[\'"]ginput_quantity[\'"][^>]*)>/i', + function ( $matches ) { + $inputTag = $matches[0]; + + // Check if the input has a decimal value, and if does not have 'any'. + if ( preg_match('/\bvalue=[\'"]([\d]+\.[\d]+)[\'"]/i', $inputTag, $valueMatch ) ) { + if ( ! preg_match('/\bstep=[\'"]any[\'"]/i', $inputTag ) ) { + $inputTag = preg_replace( '/ Date: Mon, 10 Mar 2025 15:03:08 +0530 Subject: [PATCH 3/3] `gw-quantity-as-decimal.php`: Fixed an issue with Calculation Product field not editable with decimal values. --- gravity-forms/gw-quantity-as-decimal.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/gravity-forms/gw-quantity-as-decimal.php b/gravity-forms/gw-quantity-as-decimal.php index b2ad6add5..5272960aa 100644 --- a/gravity-forms/gw-quantity-as-decimal.php +++ b/gravity-forms/gw-quantity-as-decimal.php @@ -94,6 +94,10 @@ function modify_quantity_input_tag( $markup, $field, $value, $lead_id, $form_id } function fix_content( $content, $field, $value, $lead_id, $form_id ) { + if ( ! $this->is_enabled_field( $field ) ) { + return $content; + } + // ensure the step is 'any' for any fields that have a decimal value. return preg_replace_callback( '/]*class=[\'"]ginput_quantity[\'"][^>]*)>/i',