Would it be possible to add a maxlength option to the number component? For example you may want to add sort code as a field which has a set number of characters and it would be a nicer user experience rather than relying on the form validation to check the number of characters?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

sumitmadan’s picture

Version: 7.x-4.9 » 7.x-4.x-dev
Status: Active » Needs review
FileSize
1.34 KB
rviner’s picture

Thanks,

I believe there was one piece missing:

'maxlength' needed to be added to the foreach loop in function theme_webform_number.

sumitmadan’s picture

Right. :)

DanChadwick’s picture

I'm on the fence with this feature. Number components are really intended for real numbers, not ids and sort codes which just happen to contain only digits. We try to keep webform simple, and this could always be added in the theme layer. I also haven't seen this requested before.

rviner’s picture

The latest patch has been tested and works.

It just happens I'm building an online direct debit form and thought it would be good to have the maxlength property added. Would your preferred solution be to carry on using the number component for ids and account numbers but to add the maxlength in the theme layer unless this should be part of another component?

DanChadwick’s picture

Status: Needs review » Closed (won't fix)

I don't think number components add valuable functionality for things like credit card numbers, bank account numbers, and so forth. I would recommend a regular text field, with additional validation added in custom code or the webform validation add-on module.

Number components are intended for things like # of room or age or real number (123.45). That's why I'm not sure that setting a max length is a feature that is compelling enough to include webform itself.

You can add the attribute yourself, either in the theme layer or with HOOK_webform_client_form_alter() or HOOK_webform_client_form_NID_alter().

Absent an argument that lots of people want this, I'm closing this feature request.