Rhett
Rhett

Reputation: 11

How to make a checkbox have checked be non null and unchecked be null

I have a date column that i've turned into a checkbox. How do I make it so when the date isn't null the checkbox is checked and if it is null then make it unchecked?

Upvotes: 0

Views: 590

Answers (1)

Littlefoot
Littlefoot

Reputation: 143033

I'd rather keep my DATE column as is, but make it hidden. Create another - checkbox item - and create (two?) trigger(s):

  • POST-QUERY (which fires when you query existing data)
  • WHEN-VALIDATE-ITEM (which fires when you modify data on the screen)
    • if you keep the date column hidden, maybe you don't need it. Or, you do if that date column is modified by some process

Trigger code is simple (presuming that 0 means "not checked" and 1 means "checked"):

:block.checkbox_item := case when :block.date_column is null then 0
                             else 1
                        end;

If your Forms version doesn't speak CASE, use DECODE instead (it requires the SELECT statement):

select decode(:block.date_column, null, 0, 1)
  into :block.checkbox_item
  from dual;

Upvotes: 2

Related Questions