Browse Source

Fixes #4371: Active form client validation wasn't working in case of two models having same named fields

When rendering multiple models in the same ActiveForm if any of the field names in the two models is the same then the corresponding attribute in the yiiActiveForm object in yiiActiveForm.js (ie $('form').data('yiiActiveForm').attributes) of the first rendered model is overwritten by the attribute of the last model causing the client-side validation for the overwritten field not to run at all. Example: given two models Car and Owner with attributes {make, age} and {name, age} then if the Car is rendered first its age attribute will not have any client validation.
tags/2.0.0-rc
abrahamy 10 years ago committed by Alexander Makarov
parent
commit
b7cad9df3d
  1. 1
      framework/CHANGELOG.md
  2. 2
      framework/widgets/ActiveField.php

1
framework/CHANGELOG.md

@ -69,6 +69,7 @@ Yii Framework 2 Change Log
- Bug #4241: `yii\widgets\Pjax` was incorrectly setting container id (mitalcoi)
- Bug #4276: Added check for UPLOAD_ERR_NO_FILE in `yii\web\UploadedFile` and return null if no file was uploaded (OmgDef)
- Bug #4342: mssql (dblib) driver does not support getting attributes (tof06)
- Bug #4371: Active form client validation wasn't working in case of two models having same named fields (abrahamy)
- Bug #4409: Upper case letters in subdirectory prefixes of controller IDs were not properly handled (qiangxue)
- Bug #4412: Formatter used SI Prefixes for base 1024, now uses binary prefixes (kmindi)
- Bug #4427: Formatter could do one division too much (kmindi)

2
framework/widgets/ActiveField.php

@ -195,7 +195,7 @@ class ActiveField extends Component
{
$clientOptions = $this->getClientOptions();
if (!empty($clientOptions)) {
$this->form->attributes[$this->attribute] = $clientOptions;
$this->form->attributes[Html::getInputId($this->model, $this->attribute)] = $clientOptions;
}
$inputID = Html::getInputId($this->model, $this->attribute);

Loading…
Cancel
Save