diff --git a/gravity-forms/gw-quantity-as-decimal.php b/gravity-forms/gw-quantity-as-decimal.php index 9daada007..5272960aa 100644 --- a/gravity-forms/gw-quantity-as-decimal.php +++ b/gravity-forms/gw-quantity-as-decimal.php @@ -43,11 +43,17 @@ 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 ); } function allow_quantity_float( $result, $value, $form, $field ) { @@ -87,6 +93,30 @@ function modify_quantity_input_tag( $markup, $field, $value, $lead_id, $form_id return $markup; } + 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', + 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( '/