Problem/Motivation

When use the module with a Decimal field type, and the configuration for the decimal separator is set to comma ",". The module does not take into account the field configuración in the validation process. Always assume dots ".". Because instead use the field configuration for validate the input, use the generic php function "is_number".

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

richardrodriguez21 created an issue. See original summary.

richardrodriguez21’s picture

Assigned: richardrodriguez21 » Unassigned
Status: Active » Needs review
FileSize
915 bytes
jensschuppe’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

I can confirm the patch is working, therefore setting status to RTBC.

Also raising priority according to the issue priority guidelines ("validation errors for regular form submissions").

jensschuppe’s picture

Attaching a patch for Version 7.x-2.24 for those who also need this with the current stable version.

jensschuppe’s picture

Status: Reviewed & tested by the community » Needs review
FileSize
3.77 KB

Actually this is not enough for handling number_decimal fields correctly. The Number module's widget validation handler for number_decimal and number_float elements sets the form value to an actual float value, which Select (or other) is missing, leading to an incorrect value being saved for the field, if a comma is used as the decimal separator.

This e.g. causes Rules not being able to do calculations with the value, which is the scenario I'm using this module in.

I'm attaching a patch for the 7.x-2.24 version, since that's what we're using. Maybe someone can adapt that to the current 3.x-dev branch. I'm therefore not scheduling the patch for automatic testing.

Basically, this calls the $field['module'] . '_field_widget_form' function for the field type when building the "other" sub field, so that #element_validate properties are being registered on the text field and processed when validating the field. Additionally, the manual validation code in select_or_other_field_widget_validate() is not necessary anymore for number fields. Since the "other" sub field is validated again by Select (or other) without using the #element_validate scheme, the value is to be retrieved from the $form_state['values'] array before validating.

This has not been tested with all combinations of field types and widgets, however.

jensschuppe’s picture

Note that there is no validation at all for the "allowed values" field on the field configuration form.

Those values used to be validated with the manual validation code my last patch removes, but this doesn't seem correct in the first place, since this causes validation errors for incorrect pre-defined field options (leaving the user without a clue why selectable values are invalid). This should be done in a way List module fields handle allowed values.

daften’s picture

Status: Needs review » Closed (outdated)

Closing as outdated because no activity in a long time and Drupal 7 goes EOL soon. Feel free to re-open if needed.