Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
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".
Comment | File | Size | Author |
---|---|---|---|
#5 | select_or_other-field_validation_fails_number_float_decimal_separator-2891626-5-D7.patch | 3.77 KB | jensschuppe |
#2 | 2891626-2.patch | 915 bytes | richardrodriguez21 |
|
Comments
Comment #2
richardrodriguez21 CreditAttribution: richardrodriguez21 as a volunteer commentedComment #3
jensschuppe CreditAttribution: jensschuppe commentedI 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").
Comment #4
jensschuppe CreditAttribution: jensschuppe commentedAttaching a patch for Version 7.x-2.24 for those who also need this with the current stable version.
Comment #5
jensschuppe CreditAttribution: jensschuppe commentedActually this is not enough for handling
number_decimal
fields correctly. The Number module's widget validation handler fornumber_decimal
andnumber_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 inselect_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.
Comment #6
jensschuppe CreditAttribution: jensschuppe commentedNote 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.
Comment #7
daften CreditAttribution: daften at Dropsolid commentedClosing as outdated because no activity in a long time and Drupal 7 goes EOL soon. Feel free to re-open if needed.