Two little snippets this morning (been busy already).
Firstly, form widget errors and I18n...
Brilliant stuff - if you add the error string you've defined in your form class into your I18n catalogue, it'll automatically translate. No further work needed!
Secondly - and this a little pointer :) I had updated a choice widget to set a default value. However, I noticed that even though the HTML was showing it as selected, Firefox was still showing the previous 'default' - the first option in my alphabetical list.
Clearing cookies for the site (presumably so a new session was generated) resolved the issue and displayed the expected default item.
Showing posts with label errors. Show all posts
Showing posts with label errors. Show all posts
Monday, 18 January 2010
Friday, 15 January 2010
Custom Validators and messages
Only a quick one now but there's a couple of points here that are worth noting. Especially as I've just been going round in circles for 30 minutes trying to get my custom message to display when a Doctrine form field was empty.
To be fair, I'm not confident it was due to it being a Doctrine field but anyway...
so...
1. If you use the 'addMessage()' method to add a custom method for an error code that is part of the default messages array within the validator base it WON'T get overwritten!!! If a default message exists it will always take precedence over the new version....
2. It's also worth remembering that the sfValidatorError (that your validator should extend from) class has it's clean() method called and this, in turn, calls the doClean() method. During the clean() method however, the isEmpty() method is called if the 'required' option is set to true. If the isEmpty() method returns true then your doClean() method won't ever be called... The way to get around this is to do one of the following:
a) set the 'required' option to false... not ideal if your value is required.
b) override the isEmpty() method to always return false and allow your doClean code to be called.
Done & Done
To be fair, I'm not confident it was due to it being a Doctrine field but anyway...
so...
1. If you use the 'addMessage()' method to add a custom method for an error code that is part of the default messages array within the validator base it WON'T get overwritten!!! If a default message exists it will always take precedence over the new version....
2. It's also worth remembering that the sfValidatorError (that your validator should extend from) class has it's clean() method called and this, in turn, calls the doClean() method. During the clean() method however, the isEmpty() method is called if the 'required' option is set to true. If the isEmpty() method returns true then your doClean() method won't ever be called... The way to get around this is to do one of the following:
a) set the 'required' option to false... not ideal if your value is required.
b) override the isEmpty() method to always return false and allow your doClean code to be called.
Done & Done
Labels:
doctrine,
error messages,
errors,
guide,
howto,
php,
symfony,
tutorial,
validators
Subscribe to:
Posts (Atom)