diff --git a/src/controllers/ItemController.php b/src/controllers/ItemController.php index 11c83bd..b5a9a31 100644 --- a/src/controllers/ItemController.php +++ b/src/controllers/ItemController.php @@ -82,7 +82,7 @@ public function actionSave() { $item = null; - if (isset($_POST['ItemForm']['oldName'])) { + if (isset($_POST['ItemForm']['oldName']) && $_POST['ItemForm']['oldName'] !== '') { $item = $this->findItem($_POST['ItemForm']['oldName']); } diff --git a/src/models/ItemForm.php b/src/models/ItemForm.php index 52de170..9d31b94 100644 --- a/src/models/ItemForm.php +++ b/src/models/ItemForm.php @@ -76,14 +76,14 @@ public function rules() [['name', 'type'], 'required'], [ ['name'], - 'unique', + 'uniqueName', 'when' => function () { return $this->isNewRecord; } ], [ ['oldName'], - 'unique', + 'uniqueName', 'when' => function () { return !$this->isNewRecord && $this->name != $this->oldName; } @@ -94,7 +94,7 @@ public function rules() ]; } - public function unique() + public function uniqueName() { $authManager = Yii::$app->authManager; $value = $this->name;