-
-
Notifications
You must be signed in to change notification settings - Fork 251
New issue
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
Custom rule always prepends {field} to the error message? #221
Comments
There is a (somewhat illogical) way around this. If you define the message where you use the rule, {field} is not automatically prepended: Valitron\Validator::addRule('postcode', function($field, $value, array $params, array $fields) {
return false;
}, 'Please enter a valid postcode');
$v = new Valitron\Validator(['pc'=>3070]);
$v->rule('postcode', 'pc')->message('Please enter a valid postcode'); I'm not a big fan of the automatic prepending myself, and there have been some steps taken to fix it a little bit, but removing it would be a breaking change I'm afraid |
Understood, thanks for the quick response. I'll probably just reword my error for now so it's like "Postcode must be valid". |
@johnshepherd, you can also use something like: After this Pullrequest: #210, if word |
@johnshepherd I think this problem is still relevant. It's annoying if we want to add generic message. Valitron\Validator::addRule('alwaysFail', function($field, $value, array $params, array $fields) {
return false;
}, 'Everything you do is wrong. You fail.'); The message will be :
@willemwollebrants If we add a setting like this for example: (which was true by default)
and check this setting before add the prepend, we can remove the prepend without break anything, isn't it ? |
My first reaction is: great idea, that might just work :) Maybe we should also make it possible to override this in the constructor so that it works the same as $lang and $langDir. |
Yes, good idea :) |
I created a PR for this, it applies the prepend toggle to all fieldnames, #309 |
I would like to suggest a better implementation of the logic for Method:
Method: So we have the option to use the |
Hello!
Having a little issue when adding a custom rule. Line 1127 of Validator.php does this:
'message' => '{field} ' . $message
This means when I add a custom rule like:
The error message is:
Happy to submit a PR for this if it is incorrect?
The text was updated successfully, but these errors were encountered: