nette / bootstrap

🅱 The simple way to configure and bootstrap your Nette application.
https://doc.nette.org/bootstrap
Other
663 stars 36 forks source link

Fixed NetteExtension form messages configuration #26

Closed castamir closed 9 years ago

castamir commented 9 years ago

Fixed selectbox validator message configuration, enables to config custom validator messages

castamir commented 9 years ago

@xificurk you reffered to https://github.com/nette/nette/pull/1222

I wanted to achieve 2 things: 1) avoid writing fully clasified class name for existing nette\forms\form and nette\forms\controls\selectbox validators if possible 2) allow define another validators, which do not belong to nette\forms\validator::$messages but I wanted to setup them on the same place

All I need is an example of your custom validatos if you use them. I'll modify code if needed.

castamir commented 9 years ago

What about this?

xificurk commented 9 years ago

@castamir Thanks for finding the right issue, nettet/nette#1222 is the one! ;-) I think it does more or less fulfill what you wanted: ad 1) Nette\Forms\Form related messages can be set as you want. Usually, you don't want/need to override the message for Nette\Forms\Controls\SelectBox::VALID (there is no real use case where the message should be displayed to a user). Even if you do want to change the default message, you can, it's just a bit (32) more characters ;-) ad 2) I'm not sure what do you mean by "which do not belong to nette\forms\validator::$messages". Custom validation rules can be defined the same way as Nette ones. Just add const RULE = 'NS\Validator::validateRule'; to a control, then you can use $control->addRule(Validator::RULE) and set the default message in config by 'NS\Validator::RULE': Message

castamir commented 9 years ago

OK, fixed. Code is very similar to https://github.com/nette/nette/pull/1222.

castamir commented 9 years ago

commits joined into a single commit

xificurk commented 9 years ago

Great, I think this is good to go :+1:

castamir commented 9 years ago

I additional note: this solution uses Validator::$messages instead of deprecated Rules::$defaultMessages, but I'm not so sure that Validator::$messages is already in stable version