From b5b2ce16c589b0843d5617fb412ffde2bd402a62 Mon Sep 17 00:00:00 2001 From: Rico Leuthold Date: Fri, 10 Apr 2020 12:49:49 +0200 Subject: [PATCH 1/4] Display labels (placeholders for array fields) instead of field names in error messages. --- .DS_Store | Bin 6148 -> 10244 bytes .../views/array-fields/error-help.blade.php | 2 +- src/FormComponent.php | 25 +++++++++++++----- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.DS_Store b/.DS_Store index 57b0b98a99af27c036a0fef2f26c975ffb8c3fc1..be07ca57a0854fa5f5c37a16d1578e9f8a79d1ef 100644 GIT binary patch literal 10244 zcmeHMYit}>6+XvyoSDufzIGqkwVmvyCW+H7$vTehxa6_6H?3W}#B`m;c{=-;I-{<4 zmYrEUiR;!XNI*;YMMGL1MIfF*z>lV_cuGZ-1`wcj5dtZdcnBokhzjxe0q5R3JKpsp z4MHtZHFq_0?%Z=9XU=^0eD~f30PHVjIsn1|pwPu7)9JQM;(C59Ni}XsD@mmGke%#E zq^+s^lA3;j?*ZQfz6X2{_#W^*aJ_hdIGZO$lhVKY9`HTjd%*Jmj}KwGxQw}SUP=)< z=q9!RBrX*!kbhj8Nn^Sq%trv6Uyp*yzpu71%cVu*T zC@4m!{==d=U`$H??t8%Zz)}zJy?Y&OgGn&KsouZ;=$=a5logMsvQ~=9l*n(}j_(OS z-&d{ATveYxRdF^TCvQEZ!GavzPh(G3j}4Df-&Oj`@t^DR#$Qxt!G@LURM{bejS2-Y zz$ROYluPq`YR1mHZ+khF&ziOqjs65{YU@_juU1t0tx=9APFXVvC+QUJ{$$}Oe;Q3X zr&4Zy%(AjxKAF1DG-f8)O#@cWNt!vMAR3z)gQ^@mWacu~OutpkWo*$;LMr$;>I4hS z&i3?nMZ(=((YZ)?wx=f=3GeLeo|{vZb(=c&44s@hb9VN@xrd%0mr+7DLPCRl_U=zo zZkboDcKq&<6>8bj1JWTiUoJc3XP!fD(DXI>;LzaR`p5)pnx=O>katWgXWwTOY?2eK z!6yF{j#XU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E zyG88EHLrK7l>>zN`Tzcv|Nnoz&G7s8J>Yxb|L6g%iznj!WI%Zbz1S9hToCUg@gdL+ehJU#H^cyW$EW#t0|-Y!PvT+T~LIZAK*p8{T>t<8 delta 167 zcmZn(XfcprU|?W$DortDU=RQ@Ie-{MGjdE!6q~50D9QxlfW(Rml5+BsfV`7Q1rrmO zPc~3tnS544g^h!YgNv7I@^^_OISvj^4$gQ1iRx-gV^bXkBNNM79ffLha|0a(GXu-X z<&rj&r^pv?ESS%_n4N<|kQrzg5D0Js30IJn8xy}XPv%##ob00_%?ffD!{&INIm`g1 C=pp6+ diff --git a/resources/views/array-fields/error-help.blade.php b/resources/views/array-fields/error-help.blade.php index 07e4d39..65be51d 100644 --- a/resources/views/array-fields/error-help.blade.php +++ b/resources/views/array-fields/error-help.blade.php @@ -1,6 +1,6 @@ @error($field->key . '.' . $key . '.' . $array_field->name) @elseif($array_field->help) {{ $array_field->help }} diff --git a/src/FormComponent.php b/src/FormComponent.php index 29129fb..9ad8d09 100644 --- a/src/FormComponent.php +++ b/src/FormComponent.php @@ -66,7 +66,25 @@ public function updated($field) public function submit() { - $this->validate($this->rules()); + + $attributes = []; + + /** @var Field $field */ + foreach ($this->fields() as $field) { + + if ($field->type === 'array') { + + /** @var Field $arrayField */ + foreach ($field->array_fields as $arrayField) { + $attributes[$field->key . '.*.' . $arrayField->name] = $arrayField->placeholder ?? $arrayField->name; + } + + } else { + $attributes[$field->key] = $field->label; + } + } + + $this->validate($this->rules(), [], $attributes); $field_names = []; foreach ($this->fields() as $field) $field_names[] = $field->name; @@ -75,11 +93,6 @@ public function submit() $this->success(); } - public function errorMessage($message) - { - return str_replace('form data.', '', $message); - } - public function success() { $this->form_data['password'] = bcrypt($this->form_data['password']); From 2393c51928c4433af83647873722ddf65d5c2751 Mon Sep 17 00:00:00 2001 From: Rico Leuthold Date: Fri, 10 Apr 2020 14:38:36 +0200 Subject: [PATCH 2/4] Removed Real-time Validation --- src/FormComponent.php | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/FormComponent.php b/src/FormComponent.php index 9ad8d09..77f5c6e 100644 --- a/src/FormComponent.php +++ b/src/FormComponent.php @@ -59,11 +59,6 @@ public function fields() ]; } - public function updated($field) - { - $this->validateOnly($field, $this->rules(true)); - } - public function submit() { From 5cdd4fdfbe2efd388ee7de8a55885396e8e528ff Mon Sep 17 00:00:00 2001 From: Rico Leuthold Date: Sat, 11 Apr 2020 10:14:42 +0200 Subject: [PATCH 3/4] Display labels in Real-time Validation --- src/FormComponent.php | 46 ++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/src/FormComponent.php b/src/FormComponent.php index 77f5c6e..986ae7d 100644 --- a/src/FormComponent.php +++ b/src/FormComponent.php @@ -59,27 +59,15 @@ public function fields() ]; } - public function submit() + public function updated($field) { - - $attributes = []; - - /** @var Field $field */ - foreach ($this->fields() as $field) { - - if ($field->type === 'array') { + $this->validateOnly($field, $this->rules(true), [], $this->attributes()); + } - /** @var Field $arrayField */ - foreach ($field->array_fields as $arrayField) { - $attributes[$field->key . '.*.' . $arrayField->name] = $arrayField->placeholder ?? $arrayField->name; - } + public function submit() + { - } else { - $attributes[$field->key] = $field->label; - } - } - - $this->validate($this->rules(), [], $attributes); + $this->validate($this->rules(), [], $this->attributes()); $field_names = []; foreach ($this->fields() as $field) $field_names[] = $field->name; @@ -116,4 +104,26 @@ public function saveAndGoBackResponse() { return redirect()->route('users.index'); } + + public function attributes() + { + $attributes = []; + + /** @var Field $field */ + foreach ($this->fields() as $field) { + + if ($field->type === 'array') { + + /** @var Field $arrayField */ + foreach ($field->array_fields as $arrayField) { + $attributes[$field->key . '.*.' . $arrayField->name] = $arrayField->placeholder ?? $arrayField->name; + } + + } else { + $attributes[$field->key] = $field->label; + } + } + + return $attributes; + } } From d8cb06bf501119719093a9a69bd53ac09ba05abb Mon Sep 17 00:00:00 2001 From: Rico Leuthold Date: Sat, 11 Apr 2020 10:26:22 +0200 Subject: [PATCH 4/4] Deleted .DS_Store --- .DS_Store | Bin 10244 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store deleted file mode 100644 index be07ca57a0854fa5f5c37a16d1578e9f8a79d1ef..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10244 zcmeHMYit}>6+XvyoSDufzIGqkwVmvyCW+H7$vTehxa6_6H?3W}#B`m;c{=-;I-{<4 zmYrEUiR;!XNI*;YMMGL1MIfF*z>lV_cuGZ-1`wcj5dtZdcnBokhzjxe0q5R3JKpsp z4MHtZHFq_0?%Z=9XU=^0eD~f30PHVjIsn1|pwPu7)9JQM;(C59Ni}XsD@mmGke%#E zq^+s^lA3;j?*ZQfz6X2{_#W^*aJ_hdIGZO$lhVKY9`HTjd%*Jmj}KwGxQw}SUP=)< z=q9!RBrX*!kbhj8Nn^Sq%trv6Uyp*yzpu71%cVu*T zC@4m!{==d=U`$H??t8%Zz)}zJy?Y&OgGn&KsouZ;=$=a5logMsvQ~=9l*n(}j_(OS z-&d{ATveYxRdF^TCvQEZ!GavzPh(G3j}4Df-&Oj`@t^DR#$Qxt!G@LURM{bejS2-Y zz$ROYluPq`YR1mHZ+khF&ziOqjs65{YU@_juU1t0tx=9APFXVvC+QUJ{$$}Oe;Q3X zr&4Zy%(AjxKAF1DG-f8)O#@cWNt!vMAR3z)gQ^@mWacu~OutpkWo*$;LMr$;>I4hS z&i3?nMZ(=((YZ)?wx=f=3GeLeo|{vZb(=c&44s@hb9VN@xrd%0mr+7DLPCRl_U=zo zZkboDcKq&<6>8bj1JWTiUoJc3XP!fD(DXI>;LzaR`p5)pnx=O>katWgXWwTOY?2eK z!6yF{j#XUvRq>Ii*;oMYZ^8UMq!s!p}92}3LfQ}fr3Hzj3OIs4z}xKHd&^y zq*`idWKF?{zD;4aI`#nJK{So(JAwzZ$&`^*Sw=SN(tCo3rlnU^HY^M8(02#N>ELaO zOt#6|h%DY0>R>nzN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