Problem/Motivation
When using a telephone element on a webform without setting the "placeholder" attribute, a javascript error is thrown upon validation: "Uncaught TypeError: str is undefined"
Steps to reproduce
Add a telephone element to a webform, do not specify a placeholder. Fill out the form with an incorrect phone number, the validation error message triggers the js error.
Proposed resolution
In webform.element.telephone.js:
if (!$telephone.intlTelInput('isValidNumber')) {
$telephone.addClass('error');
var message = Drupal.t('The phone number is not valid. (e.g. @example)', {'@example': $telephone.attr('placeholder')});
$error.html(message).show();
return false;
}
Ensure that the placeholder attribute exists/has a value, otherwise do not use it as argument for the message.
Remaining tasks
Write patch, review, test, commit.
User interface changes
The validation error message might change a bit if there is no placeholder attribute
API changes
None.
Data model changes
None.
| Comment | File | Size | Author |
|---|---|---|---|
| #6 | webform.webform.issue_3214708 (1).yml | 5 KB | jrockowitz |
| #3 | 3214708-3.patch | 949 bytes | jrockowitz |
| #3 | 3214708-3.patch | 949 bytes | jrockowitz |
| #3 | webform.webform.issue_3214708.yml | 4.71 KB | jrockowitz |
Comments
Comment #2
mr.baileysComment #3
jrockowitz commentedI am not able to replicate this issue using the attached webform.
Attached is a patch that should solve this issue.
Comment #4
jrockowitz commentedComment #5
paulocsI could not reproduce the error because every country I choose seems to have placeholders.
I tried to reproduce it using both webforms attached above but no success.
Anyway I did a review in the patch and I see no problem to commit as it only checks if the
placeholderis set or not.I'll not move to RTBC because I was not able to reproduce the error.
Comment #6
jrockowitz commentedThe attached webform replicates the issue by disabling the placeholder.
The patch also fixes the issue.
Comment #7
jrockowitz commentedComment #8
jrockowitz commented