Skip to content
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

Сan't change validator text only for default message #15053

Closed
ivan-zolotavin opened this issue May 25, 2020 · 2 comments
Closed

Сan't change validator text only for default message #15053

ivan-zolotavin opened this issue May 25, 2020 · 2 comments
Labels
enhancement Enhancement to the framework

Comments

@ivan-zolotavin
Copy link
Contributor

$t1 = new \Phalcon\Validation\Validator\PresenceOf(); // default message
$t2 = new \Phalcon\Validation\Validator\PresenceOf(['Field :field is required']); // custom message

echo $t1 == $t2; // TRUE - default message or custom message in validator object? 

// i need detect default message in $t1 object

Really cool functionality in previous version Phalcon\Validation::setDefaultMessages. Any ideas how to implement this functionality?

From: #767

Thanks!

@ivan-zolotavin ivan-zolotavin changed the title Сan't change validor text only for default message Сan't change validator text only for default message May 25, 2020
@ruudboon ruudboon added 4.1.0 bug A bug report status: unverified Unverified labels May 31, 2020
@ruudboon ruudboon added enhancement Enhancement to the framework and removed bug A bug report status: unverified Unverified labels May 31, 2020
@ruudboon
Copy link
Member

I'm not exactly sure what your request is, could you elaborate on this? Or do you mean something like this:

$validation->add(
    'name',
    new PresenceOf(
        [
            'message' => 'The name is required',
        ]
    )
);

https://docs.phalcon.io/4.0/en/validation

@ivan-zolotavin
Copy link
Contributor Author

I mean in the file maybe don’t unset options for messages?

https://github.com/phalcon/cphalcon/blob/master/phalcon/Validation/AbstractValidator.zep#L55

If don’t unset message options:

$t1 = new \Phalcon\Validation\Validator\PresenceOf(); // default message
$t2 = new \Phalcon\Validation\Validator\PresenceOf(['message' => 'Field :field is required']); // custom message
        
var_dump($t1 == $t2); // FALSE – need this for detect custom message
        
// expected: NULL|FALSE - empty message for default text (not set)
var_dump($t1->getOption('message') == NULL);
// expected: text message - has custom message (developer set this message)
var_dump($t2->getOption('message') == 'Field :field is required');        

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to the framework
Projects
Archived in project
Development

No branches or pull requests

2 participants