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.
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?
Comment | File | Size | Author |
---|---|---|---|
#3 | add_maxlength_option_to-2498939-3.patch | 1.8 KB | sumitmadan |
#1 | add_maxlength_option_to-2498939-1.patch | 1.34 KB | sumitmadan |
Comments
Comment #1
sumitmadan CreditAttribution: sumitmadan commentedComment #2
rviner CreditAttribution: rviner commentedThanks,
I believe there was one piece missing:
'maxlength' needed to be added to the foreach loop in function theme_webform_number.
Comment #3
sumitmadan CreditAttribution: sumitmadan commentedRight. :)
Comment #4
DanChadwick CreditAttribution: DanChadwick commentedI'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.
Comment #5
rviner CreditAttribution: rviner commentedThe 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?
Comment #6
DanChadwick CreditAttribution: DanChadwick commentedI 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.