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

Comments

crystalgrafix created an issue. See original summary.

tannguyenhn’s picture

crystalgrafix
Are you implementing a hook form alter or hook form ?

Dev1.addweb’s picture

Status: Active » Needs review
StatusFileSize
new552 bytes
new17.16 KB
new9.38 KB

Apply 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

crystalgrafix’s picture

Thanks Deepali! Your patch is doing the trick.

Dev1.addweb’s picture

Status: Needs review » Reviewed & tested by the community

Thanks crystalgrafix! Happy to know that efforts I put in to resolved the issue worked for you.

Would be awaiting for credit on this :)

quicksketch’s picture

Status: Reviewed & tested by the community » Needs work

Hi @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.

liam morland’s picture

Version: 7.x-4.14 » 7.x-4.x-dev
Status: Needs work » Closed (outdated)

Drupal 7 is no longer supported. If this applies to a supported version, please re-open.

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.