Skip to content

Commit c3d72ed

Browse files
authored
HP-1728: add partno exists validation when create model for better end-user convenience (#163)
1 parent 6c6b521 commit c3d72ed

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/models/Model.php

+17
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,23 @@ public function rules()
103103

104104
// Create
105105
[['type', 'brand', 'model', 'partno'], 'required', 'on' => 'create'],
106+
[
107+
['partno'],
108+
function ($attribute) {
109+
$exists = self::batchPerform('search', [
110+
'partno' => $this->{$attribute},
111+
'count' => true,
112+
'show_deleted' => true,
113+
]);
114+
if ($exists) {
115+
$this->addError(
116+
$attribute,
117+
Yii::t('hipanel:stock', "$attribute with that name already exists")
118+
);
119+
}
120+
},
121+
'on' => 'create'
122+
],
106123

107124
// Update
108125
[['model', 'partno'], 'required', 'on' => 'update'],

0 commit comments

Comments
 (0)