From f4c797937fe2463e18b23bf64385faa54bd2d4fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Zapletal?= Date: Tue, 9 Apr 2024 23:10:17 -0600 Subject: [PATCH] Improved admin create form --- src/Recipe/AdminRecipe.php | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Recipe/AdminRecipe.php b/src/Recipe/AdminRecipe.php index a57ded7..ba8d340 100644 --- a/src/Recipe/AdminRecipe.php +++ b/src/Recipe/AdminRecipe.php @@ -5,6 +5,7 @@ use Megio\Collection\ReadBuilder\ReadBuilder; use Megio\Collection\RecipeRequest; +use Megio\Collection\WriteBuilder\Field\Base\EmptyValue; use Megio\Collection\WriteBuilder\WriteBuilder; use Megio\Collection\WriteBuilder\Field\EmailField; use Megio\Collection\WriteBuilder\Field\PasswordField; @@ -37,7 +38,6 @@ public function readAll(ReadBuilder $builder, RecipeRequest $request): ReadBuild public function create(WriteBuilder $builder, RecipeRequest $request): WriteBuilder { - //$builder-> return $builder ->add(new EmailField('email', 'E-mail', [new RequiredRule()])) ->add(new PasswordField('password', 'Password', [new RequiredRule()])); @@ -45,8 +45,15 @@ public function create(WriteBuilder $builder, RecipeRequest $request): WriteBuil public function update(WriteBuilder $builder, RecipeRequest $request): WriteBuilder { + $pwf = new PasswordField(name: 'password', label: 'Heslo'); + + // Do not show password on form rendering + if ($request->isFormRendering()) { + $pwf->setValue(new EmptyValue()); + } + return $builder ->add(new EmailField('email', 'E-mail', [new RequiredRule()])) - ->add(new PasswordField('password', 'Password')); + ->add($pwf); } } \ No newline at end of file