Editor: Upper Case On Submit
Editor: Upper Case On Submit

Hello,
I am searching for the proper syntax to use in order to turn edited fields into uppercase when you submit the edit.
I have seen another question and Allan had mentioned using setFormatter uppercase(), but no matter what I try, I get an error.
I have tried the following...
Field::inst( 'artist' )
->setFormatter(uppercase())
Field::inst( 'artist' )
->setFormatter('Format::uppercase')
Field::inst( 'artist' )
->setFormatter('Format::UppercaseString')
Field::inst( 'artist' )
->getFormatter('Format::UppercaseString')
->setFormatter('Format::UppercaseString')
The error speaks to the method not being defined in Field.php (lib/Editor/Field.php). Do I need to write this function? Or I am just not setting this properly?
Thanks for your help.
This question has an accepted answers - jump to answer
Answers
This example here should help. It's using a function called
CapitaliseFirstLetter
, which is then called in thesetFormatter
. Hopefully that'll get you going, if not, please let us know,Colin
Hi Colin,
So write it my self?
I did a search for the
CapitaliseFirstLetter
function in the forum and found another thread where they wrote the function to the Format.php.Following suit, I grabbed the php code related to
ucwords
which happened to bestrtoupper
. (https://www.w3schools.com/PHP/func_string_strtoupper.asp)Wrote the following to the bottom of /lib/Editor/Format.php
Added the
CapitaliseFirstLetter
function to cuz... why not? Might add the rest of those functions just for completeness.Then formatted my "PHP implementation" file like so
Low and behold, that freak'n worked!
Thank you Colin for the direction.
Regards,
Kenny
Letter manipulators I added to Format.php.
Take care!
Ha, excellent, glad all sorted - thanks for reporting back,
Colin
Rather than modifying the library file with your own methods, I’d suggest using a small anonymous function for your formatter here - see docs here.
The reason being is that with the method you’ve used every time you upgrade the libraries, you’ll need to remember to transfer over the custom methods.
Allan
Thanks Allan.
I had thought about updates overwriting my customizations (and have documented all the spots I made modifications). Perhaps it would be a feature request, but would it not be possible to create a "custom" or "includes" directory, and keep all customization in there and have the system look to that location using includes or required calls?
I'm already trying to do this with styling.
Thanks for the tip Allan!
Regards,
Kernny
Hi Kernny,
Nice idea - thanks. I’ve added it to our feature tracker.
Allan