File tree Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Expand file tree Collapse file tree 2 files changed +25
-6
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 ]);
You can’t perform that action at this time.
0 commit comments