ActiveForm: Validation delay is applied in non validateOnType
scenarios
#20217
Labels
JS
JavaScript related
validateOnType
scenarios
#20217
What steps will reproduce the problem?
Create a ActiveForm with
validationOnType = false
andvalidateOnBlur = true
.What is the expected result?
For my understanding,
validationDelay
shouldn't be used because it states:Configuring the
validationDelay
property with value0
or1
for the widget has no effect.What do you get instead?
The default validationDelay value defined in
yii.activeForm.js
is used. Therefore the applied validation delay when creating a ActiveForm withvalidateOnBlur
seems to be 200ms.Additional info
Cause in code:
In
yii.ActiveForm.js
watchAttribute()
only inif (attribute.validateOnType) {
case the validationDelay value from attribute gets passed tovalidateAttribute()
function:validateOnType:
yii2/framework/assets/yii.activeForm.js
Line 542 in 76150c5
validateOnBlur:
yii2/framework/assets/yii.activeForm.js
Line 532 in 76150c5
In
validateAttribute
function,validationDelay
is checked for empty. When empty, 200ms is used instead. When no value is passedvalidationDelay
is empty, consequently 200ms is used in validateOnBlur case:yii2/framework/assets/yii.activeForm.js
Line 591 in 76150c5
Possible duplicates
Perhaps #18422 adresses the same problem.
Why is this a Problem?
The delayed validation causes problems when using a screen reader.
When an validation error occours, the error message gets read after the description for the following input field, even when using `aria-live="assertive". After some digging we found out that the 200ms validation delay causes the screen reader to start reading the next focus first instead of directly reading out the error message.
Suggestions to resolve the issue
Idea 1:
Move validation delay from
validateAttribute
function towatchAttribute
function. The validation delay should only be used when attribute.validateOnType is true. So why keep it in validateAttribute funciton that is used in every case?Code would look something like this then:
Idea 2:
Specify a default value for
validateAttribute
'svalidationDelay
parameter.The text was updated successfully, but these errors were encountered: