Follow Us on Twitter

Checkbox in APEX without javascript

by Jan Thuis on March 18, 2010 · 3 comments

One of the favorite GUI items is the Checkbox. I use this GUI item often to enforce a ‘Yes’ or ‘No’ option.

If the item ‘Maintainable’ is checked, the database value has to become ‘Y’ and if unchecked, the database value has to become ‘N’. The underlying column definition is a mandatory varchar2(1) column which only may contain the values ‘Y’ or ‘N’.

First, create the check constraint (optional).

CONSTRAINT "OMP_DOMAINS_CHK1" CHECK (MAINTAINABLE IN ('Y', 'N')) ENABLE

Then we create the page-item ‘Maintainable’, set ‘Display As’ to Checkbox.

Because the item type of this item is ‘Checkbox’ we have to define a corresponding LOV.  Create a STATIC LOV with only 1 value. Enter to ‘Display value’:   and ‘Value: ‘Y’ This results in 1 checkbox without a suffix. Now we have only 1 checkbox, with can get two values, the ‘Y’ and the NULL.

If you submit the item unchecked, the NULL value is written to the database. This is not allowed because the underlying column is required. To avoid this error you have to create a before row trigger on the database table. This trigger translates the NULL value to ‘N’ and ensures that we don’t need any additional javasript.

create or replace trigger omp_dos_bru
before update on omp_domains
for each row
begin
  :new.maintainable := nvl(:new.maintainable,'N');
end;

This is the server-side solution. If you are not able to implement a database trigger eg autorisation reasons, there is also a client side solution in APEX.  Thanks Simon Boorsma for this sensible supplement. The only thing you have to do is to define a computation on submit after validations.

Checkbox in APEX without javascript, 4.5 out of 5 based on 2 ratings

Ratings:
VN:F [1.9.13_1145]
Rating: 4.5/5 (2 votes cast)
Tags: ,

{ 3 comments… read them below or add one }

s1m0n March 18, 2010 at 2:44 pm

Why not use a computation ( on submit after validations) on the APEX screen, instead of the suggested database-trigger?

Reply

jthuis March 18, 2010 at 3:23 pm

Thanks, you are right, thats also a nice solution. I’m still learnig every day.

Reply

Shijesh December 15, 2011 at 11:54 am

HI JAN,

Can’t we define “DEFAULT” value for the column which as “N”. In this way when we the checkbox is unchecked, field will be “N” and when checked it will hold “Y”.

Regards,
Shijesh

Reply

Leave a Comment

 

Previous post:

Next post:

About Whitehorses
Company profile
Services
Technology

Whitehorses website

Home page
Whitebooks
Jobs

Follow us
Blog post RSS
Comment RSS
Twitter