1
votes

I have a checkbox item on my page (note: this is not inside a report) and I want to dynamically check the checkboxes when the page loads. I have a table which has all the checkbox types and a table which identifies which checkboxes that user has access to or in better terms should be checked.

My question is, within an Apex checkbox item how do you tell it to dynamically check a checkbox. I have it working in a report and my query looks like this:

SELECT at.name AS TITLE,
     CASE
         WHEN at.name IN (SELECT atp.name FROM preferences p) THEN apex_item.checkbox(1,at.value,'CHECKED')
         ELSE apex_item.checkbox(1,at.value, 'UNCHECKED')
      END AS CHECKBOX
FROM access_types at

Can I do something similar in an oracle apex checkbox item?

1
You can use a little bit of javascript to check a checkbox.AnBisw
@Annjawn, javascript would be an option but I need to reference my preferences table to see which checkbox should be checked. How can I do that using javascript?medium
A simple solution could be to have hidden fields and populate the fields with the preference table values. Once the hidden fields have the values, the javascript can easily read the field and based on the value of the field check the checkbox.AnBisw
@Annjawn, thank you. This would work. It just seems weird that you can not precheck a checkbox on a checkbox item list. It seems like that is something that would be important to web developers in oracle apexmedium

1 Answers

3
votes

Not sure it is exaclty what you want but if you simply need to initialize a checkbox item on page load, you can :

1 - Use the Source attribute of the checkbox item and set the following attributes :

  • Source Used : Always, replacing any existing value in session state
  • Source Type : SQL Query (return single value) or SQL Query (return colon separated value) depending if your checkbox item contains several checkboxes or not.
  • Source value or expression : your query that returns the right values.

2 - Use a Before header computation to compute your item :

  • Compute Item : Your checkbox item
  • Computation Point : Before header
  • Computation Type : SQL Query (return single value) or SQL Query (return colon separated value) depending if your checkbox item contains several checkboxes or not.
  • Computation : your query that returns the right values.

Note: I use checkboxes in reports too, but I noticed that when you have a lot of rows, it is very slower than using simple HTML checkboxes, so if you think your report is slow, I suggest you to generate simple HTML checkboxes from your query :

SELECT
  at.name AS TITLE,
  CASE WHEN at.name IN (SELECT atp.name FROM preferences p) THEN
    '<input type="checkbox" value="'||at.value||'" checked="checked" />'
  ELSE
    '<input type="checkbox" value="'||at.value||'" />'
  END AS CHECKBOX
FROM
  [...]