Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
data-nette-rules
nette/forms version: v3.0.3 nette/utils version: v3.1.1 php version: PHP 7.4.4 (cli) Reproducibility: always
nette/forms
nette/utils
require 'vendor/autoload.php'; use Nette\Forms\Form; use Nette\Utils\Html; $form = new Form; $form->addPassword('password1', 'Password:') ->addRule(Form::PATTERN, 'Must contain number', '.*[0-9].*'); $form->addPassword('password2', 'Password:') ->addRule(Form::PATTERN, Html::el()->addHtml('Must contain number'), '.*[0-9].*'); echo $form; // renders the form
<form action="" method="post"> <table> <tr> <th><label for="frm-password1">Password:</label></th> <td><input type="password" name="password1" pattern=".*[0-9].*" id="frm-password1" data-nette-rules='[{"op":":pattern","msg":"Must contain number","arg":".*[0-9].*"}]' class="text"></td> </tr> <tr> <th><label for="frm-password2">Password:</label></th> <td><input type="password" name="password2" pattern=".*[0-9].*" id="frm-password2" data-nette-rules='[{"op":":pattern","msg":"Must contain number","arg":".*[0-9].*"}]' class="text"></td> </tr> </table> </form>
Please note: data-nette-rules are the same in INPUT[name="password1] and INPUT[name="password2].
INPUT[name="password1]
INPUT[name="password2]
<form action="" method="post"> <table> <tr> <th><label for="frm-password1">Password:</label></th> <td><input type="password" name="password1" pattern=".*[0-9].*" id="frm-password1" data-nette-rules='[{"op":":pattern","msg":"Must contain number","arg":".*[0-9].*"}]' class="text"></td> </tr> <tr> <th><label for="frm-password2">Password:</label></th> <td><input type="password" name="password2" pattern=".*[0-9].*" id="frm-password2" data-nette-rules='[{"op":":pattern","msg":{"attrs":[]},"arg":".*[0-9].*"}]' class="text"></td> </tr> </table> </form>
Please note the "msg":{"attrs":[]} in INPUT[name="password2"][data-nette-rules].
"msg":{"attrs":[]}
INPUT[name="password2"][data-nette-rules]
Found a workaround:
diff --git i/src/Forms/Validator.php w/src/Forms/Validator.php index 66acfdd..6406374 100644 --- i/src/Forms/Validator.php +++ w/src/Forms/Validator.php @@ -52,7 +52,7 @@ class Validator { $message = $rule->message; if ($message instanceof Nette\Utils\IHtmlString) { - return $message; + return (string)$message; } elseif ($message === null && is_string($rule->validator) && isset(static::$messages[$rule->validator])) { $message = static::$messages[$rule->validator];
The text was updated successfully, but these errors were encountered:
b206178
renders correctly Nette\Utils\IHtmlString in data-nette-rules [Closes
24de0f3
#243]
No branches or pull requests
Environment
nette/forms
version: v3.0.3nette/utils
version: v3.1.1php version: PHP 7.4.4 (cli)
Reproducibility: always
Steps to Reproduce
Expected Result
Please note:
data-nette-rules
are the same inINPUT[name="password1]
andINPUT[name="password2]
.Actual Result
Please note the
"msg":{"attrs":[]}
inINPUT[name="password2"][data-nette-rules]
.Note
Found a workaround:
The text was updated successfully, but these errors were encountered: