ChangeCase: A Simple Apex 4.0 Plugin
A foray into Plug-Ins
To educate myself in the ways of the new Apex 4.0 Plug-Ins feature, I decided to create a simple item Plug-In which automatically converts all the text entered into the item either to uppercase or to lowercase, depending on which option the developer chooses. I’m making it available here not so much because I think it will be a useful Plug-In (though perhaps it might be if your requirement is very simple) but rather in the hope that it might be helpful to anyone else looking at Plug-Ins for the first time. I have heavily commented the code to explain what each bit is doing.
See it in action
A working example of this plugin can be seen here.
Download and install
The plugin itself can be downloaded here.
Once you have downloaded the Plug-In, you can install it by going to Shared Components > Plug-Ins > Import and following the prompt. You will then be able to create ChangeCase items in your application, choosing whether you want the contents to be automatically uppercased or lowercased.
Creating it from scratch
If, for the hell of it, you want to create this Plug-In from scratch as opposed to just downloading and installing it you can do so by following these steps.
- Within Application Builder go to Shared Components > Plug-ins and click “Create >”.
- Specify the following details and then click “Create”:
Internal Name: uk.co.tulley.changecase (or change this to be a universally unique name based on your domain name)
PL/SQL Code: Paste in the contents of this file. This contains two PLSQL functions (render_changecase and validate_changecase which we reference in the Render Function Name and Validation Function Name properties of this Plug-In). This PL/SQL code is heavily commented so should hopefully be fairly self-explanatory.
Render Function Name: render_changecase
Validation Function Name: validate_changecase
Standard Attributes: Tick the checkbox labelled “Is Visible Widget”. If you do not tick this checkbox then there will be no option to specify a Label for our ChangeCase Item Plugin when we create an instance of it in our application. Since this is essentially just a slightly-modified Text Field, we certainly want the ability to specify a label.
- Click “Custom Attributes”. When we create a new instance of our new Plug-In, we want to be able to decide whether we want the contents to be automatically uppercased or lowercased so we create a custom attribute here to allow that decision to be made.
- Click “Add Attribute”.
- Specify the following details and then click “Create”.
Label: Case Alteration Option
Type: Select List
Default Value: UPPER
Add Value button in List of Values Section: Create two entries. One with a Display Value of “Uppercase” & a Return Value of “UPPER”; and the other with a Display Value of “Lowercase” and a Return Value of “LOWER”.
- Back in Application Builder, click “Files” and then the “Upload New File” button.
- Browse for the changecase.js file that you just downloaded and then click “Upload”.
- Finally, click “Apply Changes”.
You will now be able to create ChangeCase items in your pages where you’ll be able to specify, under settings, whether you want the content automatically uppercased or lowercased.