Use APEX Shortcuts for your Clear Item Button or Link
You probably know how to add a button or link to clear the value of an item. You may have seen the button on apex.world when you search for a plug-in, for example.
You can use a Dynamic Action that executes a “Set Value” or a fairly straight-forward code like this:
<a href="javascript:$s("P1_SEARCH", "")">Clear</a>
What I like to do is define APEX Shortcuts. You find them under Shared Components > Other Components > Shortcuts
There are two Shortcuts I usually create and use them depending on how well they fit:
- A button CLEAR_BUTTON
- A text link CLEAR_LINK
Once these Shortcuts are defined I can simply type "CLEAR_BUTTON"
or "CLEAR_LINK"
in the “Post Text” field of an Item.
View the Demo Here.
Here is the end result:
return '<a class="a-Button a-Button--popupLOV lov-clear" aria-label="' || apex_lang.lang('Clear') || '" title="' || apex_lang.lang('Clear') || q'!" href="javascript:$s('#CURRENT_ITEM_NAME#','');">!'
|| '<span class="fa fa-close"></span>'
|| '</a>';
return q'!<a href="javascript:$s('#CURRENT_ITEM_NAME#','');" class="clearLink a-Button a-Button--popupLOV">!'
|| apex_lang.lang('Clear') || '</a>';
Final Note: I may be using APEX 20.1 for the screenshots, however, I’ve been using this feature since APEX 4.2!!!
PS. Thanks to Ronny Weiss correcting a typo and for reminding me that this solution doesn’t look as great with Floating Labels. What I suggest is to remove the a-Button
& a-Button--popupLOV
classes and instead turn on the “Display as Block” Template Option. The end result can be seen below. For the icon option, you can do something similar, but you may want a little more styling.
Hi Jorge,
Great post. I immediate set it to work for me!
One question: Why did you choose the Shortcut to be of type PL/SQL Function Body? While it seems to me it’s just plain text (with a substitution)
Hope to hear from you.
Hi Dick, very good observation, I’m now remembering that the shortcuts may have started life as plain or HTML shortcuts, however, once I had to use them in a translated, I switched to PL/SQL so I could use apex_lang.lang. However, if you want them translated you could also use the JS call (but that adds the JS string to every request). Thank you, I appreciate the comment
Found it myself, I overlooked the calls to apex_lang :-).
Nice tip Jorge. Already deployed into one of our apps. Thank you.
Oooh love it, thanks for sharing
Nice Post With good explanation
Thanks Jorge, great tip. I just used this in a project i’m working on.
Having issues getting the CLEAR_BUTTON to work in APEX 20.2 Cloudy 24 Theme. It wont render the check box. Yet I can get the CLEAR_LINK to work.
Any idea’s
What do people like to do for textarea fields?
Hello im junior developer of Apex oracle it is so nice solution, And how can i create link button istead of clear? Can u share me pl/sql code