kartik-v / yii2-widget-select2

Enhanced Yii2 wrapper for the Select2 jQuery plugin (sub repo split from yii2-widgets).
http://demos.krajee.com/widget-details/select2
Other
323 stars 145 forks source link

field validation is triggered on select2 widget by validation event from another field in the form #277

Closed gredek closed 5 years ago

gredek commented 5 years ago

Hi,

When using the select2 widget in a ActiveForm, configured with the 'multiple' => true option, the widget validation gets triggered automatically by the validation event/process of any other field on the form.

Reproduce: So If you have a textinput field and a select2 field (configured with the multiple option) on your form (enableClientValidation true) and both are required, when validation on the textinput kicks in , the validation on the select2 is triggerd. When I remove the 'multiple' => true option from the select2 widget, the validation is not triggered by another field, behaves as expected.

any idea what could cause this and how to fix it? Thank you.

gredek commented 5 years ago

seems like the select2 field is also being validated because it status is 3. Still figuring out why the status has changed to 3 by the validation event on another field.

gredek commented 5 years ago

ok seem to found it. the validation happend because in yii.activeForm.js a forcevalidate is enabled on the field because of this.value !== getValue($form, this) is true and with multiple option active on the select2 widget it is comparing arrays, not value, therefore the widget got triggered to validate.