making my tabular form dynamic - oracle

I have a checkbox on a tabular form. I need to be able to hide it if the submit date is not filled in and show it when a date is there. Once the checkbox has been clicked, I need to update another field based on the checkbox being clicked or when I hit the update button. is this possible on a Oracle Apex tabular form in version 4.2?

You can create dynamic actions on tabular form fields, but you need to know some Javascript / jQuery / DOM stuff as it can't be done declaratively as it can with page items.
As an example, I created a simple tabular form on the EMP table:
Using the browser's Inspect Element tool I can see that the HTML for the Ename field on row 3 looks like this:
<input type="text" name="f03" size="12" maxlength="2000" value="Ben Dev"
class="u-TF-item u-TF-item--text " id="f03_0003" autocomplete="off">
The relevant bits to note are the name "f03" and the ID "f03_0003". For all tabular form fields, the name indicates the column, and is the same for all fields in that column. The ID is made up of the name plus a string to represent the row - in this case "_0003" to represent row 3.
Similarly, the Hiredate fields are all named "f004" and have IDs like "f04_0003".
Armed with this information we can write a dynamic action. For example, let's say that whenever Ename is empty then Hiredate should be hidden, otherwise shown. In pseudo-code:
whenever an element with name "f03" is changed, the element with name "f04" on the same row should be hidden or shown.
So we can create a synamic action with a When condition like this:
Event = Change
Selection type = jQuery selector
jQuery selector = input[name="f03"]
i.e. whenever an input whose name is "f03" is changed, fire this action.
The action performed will have to be "Execute Javascript code", and the code could be:
// Get the ID of this item e.g. f03_0004
var this_id = $(this.triggeringElement).attr('id');
// Derive the ID of the corresponding Hiredate item e.g. f04_0004
var that_id = 'f04'+this_id.substr(3);
if ($(this.triggeringElement).val() == "") {
// Ename is empty so hide Hiredate
$('#'+that_id).closest('span').hide();
} else {
// Ename is not empty so show Hiredate
$('#'+that_id).closest('span').show();
}
Because Hiredate is a date picker, I needed to hide/show both the field itself and its date picker icon. I chose to do this by hiding/showing the span that contains them both. This code could have been written in many different ways.
You could apply similar techniques to achieve your aims, but as you can see it isn't trivially easy.

Related

Setting date value in an Interactive grid based on a page item

I am trying to set a interactive grid column value (which is a date) based on a page item (which is also a date). I have already tried defaulting and using dynamic action set value (jquery seletor) to set item value to the interactive grid column but it does not work how I want it to work.
I have a page item called "P_DEF_DATE" and I want to set a date column in the interactive grid to this value but I want when I change the value in the page item and I click add row on the interactive grid, it must always use whatever value I have in the page item. For example:
P_DEF_DATE = 12-JAN-2021
when I click on add row in the interactive grid, my date column must equal to P_DEF_DATE and i add a few rows based on that date but then i change the date of P_DEF_DATE to:
P_DEF_DATE = 28-JAN-2021
now I want when I click on add row in the interactive grid, I it must show this new date from the page item in the date column in the interactive grid, keeping in mind the page does not refresh and I have rows with the date 12-JAN-2021.
Thank you in advance!
I implemented same few days ago. Following is what I did.
Create Dynamic Action on Row Initialization Event, set Region to your IG
Set True Action to Execute JavaScript Code
Use code
var model = this.data.model,
rec = this.data.record,
meta = model.getRecordMetadata(this.data.recordId);
if ( meta.inserted ) {
model.setValue(rec,"COLUMN_NAME", $v("P_DEF_DATE"));
}
Replace JOB with your column name and P_DEF_DATE with you Item name
More details Here
Also, out of curiosity, why there is no number like P1, P2 in your item name ??

Oracle Apex 4.2 Tabular Form checkbox for changed column value

I have an Apex Tabular form:
ID Name Title Class ROW_EDIT <br>
1 Smith Mgr AP (checkbox)<br>
etc...
I am trying to activate the 'checkbox' ROW_EDIT column - which has a default value of Y - when the user changes the value for the tabular form column Class (Select list) in the same row. I can change the ROW_EDIT attribute to text (ie, Y) if easier...
I have no apex_items for the page to reference - all columns are tabular form.
I have researched some dynamic change events - but I can't seem to get the row-reference to set correctly.
Any help would be greatly appreciated.
Thanks
Unfortunately, last time I saw APEX 4.2 was 2 years ago and I don't have it now.
The idea is in the following:
Add onchange event to select list. I don't remember is there an easy way to do this. If not, you can create a select list manually using APEX_ITEM package. To do this, write in the source query:
select apex_item.select_list_from_lov (
p_idx => 10,
p_value => class, -- it is a name of a table column
p_lov => 'my_lov_name',
p_attributes => 'onchange="my_func.call(this);"')
from ...
In page properites (JavaScript section), create a javascript function:
function my_func () {
this.parentElement.parentElement.getElementsByTagName("input")[0].checked = true;
}
Parameter this in the function is a reference to select list. Hence, this.parentElement.parentElement - reference to row with the triggering select list, getElementsByTagName("input")[0] is a checkbox. If you have several input elements in the row, use proper index instead of 0.
How this JavaScript code works you can check here: https://codepen.io/anon/pen/NvPmPp

Counting a field value response weekly basis in Lotus Notes

I have radio button field in a form whose value can be 1 or 2 or 3. I have a made a view out of this form and there one column will contain the value of this radio button field . Whenever a customer submits the form, a new document will appear in the view. A customer can submit the form many times with different value of this radio button. Is it possible to know how many times a particular customer selected the value 1?
Yes, you can create a view where the first column is your customer name and the second column is their response. Both columns should be "categorized" meaning they'll group the like values.
For each column you can set the formula to include the number of documents within the group. For example:
CustomerName + " (" + #DocChildren + ")"
will show you "ABC Company (12)" if ABC had 12 responses.

how to code the itemchanged event and datawindows

I am using PowerBuilder classic 12.5
am having difficulties in inserting, editing, creating and printing reports.
i have a datawindow, dw_NewEmployee with dataobject, d_newrecord which is update-able.
should i use the columns to insert records through the columns or i
create single line texts on the window object
is the itemchanged event used on columns and rows on dataobject or
on single line texts... I am having trouble figuring out how to implement validation rules.
please give me an example to validate employee ID_Number
I see that you seem confused about the datawindow usage.
Let's try to summarize:
you create a new datawindow d_newrecord (say it is a grid) based on a sql select in your database, say select id_number, name from employee.
in the detail zone of the datawindow (that will be repeated for each record at runtime but that is only once in design), you need to put one column object for each column (here you will have id_number and name) these objects are both to display existing data and receive user input for editing data and inserting new records.
don't forget to set the Rows / Update properties if you need to make the dw updatable.
in the header zone of the datawindow you can have a static text associated to each column that is just here to display the column name, it does not concern table data.
in some window object, you place a datawindow control dw_newemployee where the content of the datawindow will be painted, you set d_newrecord as its dataobject.
you need to set at some point the transaction object of the dw, for example in the open() event of the window:
dw_newemployee.SetTransObject(sqlca)
dw_newemployee.Retreive() //if you are using some retreival arguments, don't forget to include them here
When you want to insert new data in your table (for example with a window button "add"), in the clicked() event of the button you call dw_newemployee.InsertRow(0) to insert at the end.
The ItemChanged() event will be triggered after one cell will be modified, you will be given the row, item (a dwobject) and new data. By choosing the returned value of the event, you can accept or reject the new data.
Here is an example for a field validation in itemchanged() event:
long ll_return_code = 0
string ls_column
ls_column = lower(dwo.name)
choose case ls_column
case "id_number"
if long(data) = 42 THEN
messagebox("validation error", "You cannot use 42 for the ID")
ll_return_code = 1 //reject and stay in cell
end if
case "name"
if data = "foobar" then
messagebox("validation error", "Do not use dummy value...")
ll_return_code = 2 //reject but allow to go elsewhere
end if
end choose
return ll_return_code

DefaultModelBinder and binding action parameters from values in a table row

What I am doing is this. I have a basic table with a button at the end of each row for "selection" of that row for further actions. My action method has two simple parameters I'll call them id1 and id2 so:
public ActionResult DoSomething(int id1, int id2)
id1 will be bound from a hidden form field outside the scope of the table, this works fine.
id2 needs to come from a hidden column from an individual row in the table depending on the button clicked representing the row that requires further processing. Make sense?
When the form posts back to the action method, id1 is set perfectly, no problem, but id2 is always the value of the hidden column from row 1. How do I detect/make DefaultModelBinder pull the hidden column value from the row from which the button is being clicked?
Thanks for the assist as I am actively trying to figure this out.
Here is the hidden table column that is rendered per row that I want to capture it's value on the post from the row from which the button was clicked:
<td style="display:none;">#Html.Hidden("id2", viewModel.id2)</td>
You could use simple hyper links instead of forms on each row. Like this:
#Html.ActionLink("link text", "DoSomething", "SomeController", new {
id1 = viewModel.id1, id2 = viewModel.id2
}, null)
which assuming default routes should generate the following link:
/somecontroller/DoSomething?id1=123&id2=456
and when you click on it the DoSomething action will be invoked with correct parameters.
If you want to do this with POST you will need multiple forms, one for each row:
#using (Html.BeginForm("DoSomething", "somecontroller"))
{
#Html.Hidden("id1", viewModel.id1)
#Html.Hidden("id2", viewModel.id2)
<input type="submit" value="OK" />
}

Resources