Skip to content

Commit 5312737

Browse files
authored
Merge pull request #39 from kuhdmitry/master
Add possibility to set attribute name the same as label
2 parents ab30b5d + af5a511 commit 5312737

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/Form.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ class Form
2424
protected $action;
2525
protected $theme;
2626
protected $class;
27-
protected $elements = [];
28-
protected $errors = [];
29-
protected $validated = false;
30-
protected $name = false;
31-
protected $isAjax = false;
27+
protected $elements = [];
28+
protected $errors = [];
29+
protected $validated = false;
30+
protected $name = false;
31+
protected $isAjax = false;
3232
protected $enctype;
33-
protected $disabled = false;
33+
protected $disabled = false;
34+
protected $useLabelAsAttributeName = false;
3435

3536
public function __construct()
3637
{
@@ -164,6 +165,18 @@ public function addClass($class)
164165
return $this;
165166
}
166167

168+
public function useLabelAsAttributeName($useLabelAsAttributeName = true)
169+
{
170+
$this->useLabelAsAttributeName = $useLabelAsAttributeName;
171+
172+
return $this;
173+
}
174+
175+
public function isUseLabelAsAttributeName()
176+
{
177+
return $this->useLabelAsAttributeName;
178+
}
179+
167180
/**
168181
* @param $name
169182
* @param string $validators

src/Form/Element.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,12 @@ public function validate($keys)
212212
$values = request($keys);
213213

214214
$validator = $validator->setData($values);
215+
216+
if ($this->form && $this->form->isUseLabelAsAttributeName() && $this->label)
217+
{
218+
$validator->setAttributeNames([$this->name => $this->label]);
219+
}
220+
215221
$validator = $validator->setRules([
216222
$this->name => $this->validators
217223
]);

0 commit comments

Comments
 (0)