Formidable icon indicating copy to clipboard operation
Formidable copied to clipboard

How to create a custom error message

Open chateaux opened this issue 5 years ago • 1 comments

So I have followed the docs here: https://formidable.readthedocs.io/en/latest/constraints/#creating-a-simple-constraint and created my own custom error constraint.

When I run the form, I get the error: Non-existent message key "some-error-key" provided

Going over the code I note this message is due to the ErrorFormatter missing the key "some-error-message" and I also note that the constructor of the class can be used to include new custom messages...

My question, however, is, how and where should a custom message be set?

chateaux avatar May 13 '19 21:05 chateaux

That depends on your application architecture. But generally you'd create the error formatter in a factory and pass it down to your view layer. Where you source your error keys and messages from is up to you. I usually use a config section for that.

DASPRiD avatar May 14 '19 01:05 DASPRiD