forms icon indicating copy to clipboard operation
forms copied to clipboard

TextBase support mixed as value

Open milous opened this issue 7 years ago • 0 comments

  • bug fix? no
  • new feature? yes
  • BC break? no

adds support for

// class without __toString method
final class User {
  // ..
}

$repo = function(string $userName): ?User {
   return new User;
}

$form = new Nette\Forms\Form;
$form->addText('user', 'Username')
  ->addFilter(function (string $userName) use ($repo) {
    return new Nette\Forms\ScalarValue($userName, $repo($userName)));
  } )
;

$form->onSuccess[] = function(Nette\Forms\Form $form, array $values): void {
  $values['user'] instanceof User || null;
};

milous avatar Apr 20 '18 15:04 milous