Hi,
When creating a Numeric field via Webform API, Min and Max values are not validated.
$form['access_required']['new_desk'] = array(
'#type' => 'webform_number',
'#title' => t('Desk Number'),
'#required' => 1,
'#attributes' => array(
'min' => '10',
'max' => '100',
'class' => array(
'numeric'
),
),
);
In the above example, even if I type -5 as the value, no error messages are shown. However, required attribute is validating correctly.
Thanks
| Comment | File | Size | Author |
|---|---|---|---|
| #3 | before.png | 9.38 KB | Dev1.addweb |
| #3 | after.png | 17.16 KB | Dev1.addweb |
| #3 | edit_webform_api_number-2799691-1.patch | 552 bytes | Dev1.addweb |
Comments
Comment #2
tannguyenhn commentedcrystalgrafix
Are you implementing a hook form alter or hook form ?
Comment #3
Dev1.addweb commentedApply following patch to make things work. Please note it will not support comma separated or decimal numbers. Let me know in case of any concerns.
Thanks
Comment #4
crystalgrafix commentedThanks Deepali! Your patch is doing the trick.
Comment #5
Dev1.addweb commentedThanks crystalgrafix! Happy to know that efforts I put in to resolved the issue worked for you.
Would be awaiting for credit on this :)
Comment #6
quicksketchHi @Deepali_Argawal, we specifically disabled the use of a "number" input field per the code comments directly above that line. See #2290029: Thousands separator creates invalid value for HTML5 Number input and #2202905: Decimal numbers with comma as placeholder fail validation in Chrome. We will need to validate that those problems do not exist, otherwise we'll just be trading one set of problems for another.
In any case, if we apply this change, we should at least update the code comments.
Comment #7
liam morlandDrupal 7 is no longer supported. If this applies to a supported version, please re-open.