Problem/Motivation

If the "Feet minimum" and "Feet maximum" settings are left blank when configuring a Webform Height input field, then filling out that form element will throw an error:

TypeError: Unsupported operand types: string - string in Drupal\Component\Utility\Number::validStep() (line 34 of core/lib/Drupal/Component/Utility/Number.php).
Drupal\Core\Render\Element\Number::validateNumber(Array, Object, Array)
call_user_func_array(Array, Array) (Line: 281)
Drupal\Core\Form\FormValidator->doValidateForm(Array, Object) (Line: 238)

Steps to reproduce

1. Create a new webform
2. Add a new element to the form of type: "Height (feet/inches)".
3. Under "Height settings" clear the "Feet minimum" and "Feet maximum" values.
4. Save the element and the form.
5. View the form.
6. Enter any value for the height field setup above, and submit the form. You will see the error listed above.

(tested with Webform 6.2.2 and Drupal 10.2 and confirmed with a clean simplytest.me instance.

Proposed resolution

This could be fixed either by making the min/max fields in the element configuration required fields. Or changing the Webform Height submodule code to treat an empty string "" as a proper null so that the 'validStep doesn't fail due to the empty string parameter.

Notes

Given that editors need to remove the default values to trigger this error means it is fairly easy to avoid, though it would still be considered a bug.
I note that this scenario was previously showing as a warning in a D9 site, but appears to now be an error with D10 that breaks the form usage.

See attached screenshots for the above.

Issue fork webform-3452185

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Gomez_in_the_South created an issue. See original summary.

Maithri Shetty made their first commit to this issue’s fork.

maithri shetty’s picture

Status: Active » Needs review
nupur badola’s picture

Status: Needs review » Reviewed & tested by the community
StatusFileSize
new125.58 KB
new38.62 KB

Reviewed the MR, No error is identified as the min and max field are mandatory fields now. Hence marking it to RTBC.

jrockowitz’s picture

The below element replicates the issue when the feet are set and not the inches.

height:
  '#type': webform_height
  '#title': height
  '#feet__min': ''
  '#feet__max': ''
jrockowitz’s picture

Status: Reviewed & tested by the community » Needs work

I want to fix the validation issue and not always require a value.

harshitthakore’s picture

StatusFileSize
new1.81 KB

Attached patch file for min__feet and max_feet properties validation on element save.

harshitthakore’s picture

Status: Needs work » Needs review
jrockowitz’s picture

Thank you for the patch from #8, but I think we can all min/max to be an empty string and deal with the validation issue via \Drupal\Core\Render\Element\Number::validateNumber.

Please review the MR, which changes the custom min/max from an empty string to NULL, which works as expected for determining the offset in \Drupal\Core\Render\Element\Number::validateNumber via $offset = $element['#min'] ?? 0.0;.

liam morland’s picture

Version: 6.2.2 » 6.3.x-dev

Needs rebase onto 6.3.x.

jrockowitz’s picture

Should this bug be addressed in 6.2.x?

liam morland’s picture

I don't mind. I was thinking of 6.2.x as security-updates-only since it goes EOL so soon along with Drupal 10.2.

jrockowitz’s picture

If the tests pass, let's merge this.

jrockowitz’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.