This discussion is archived
1 2 Previous Next 18 Replies Latest reply: Jan 25, 2013 9:55 AM by VC RSS

Deleting From  A Tabular Form With A Dynamic Action

Gus C Journeyer
Currently Being Moderated
Using Apex 4.2

Is it possible to delete a row from a tabular form using dynamic actions.

At the moment my report sql contains html and javasript for a delete button
'<input type="button" name="Delete" value="Delete"  onclick="del(''delete'','''||a.applicationname||''')">' A2
I then have javascript in my page header
function del(Request, Name){
var answer=confirm("Do you really want delete application "+Name+"?\r\n* Provider assignments will be deleted\r\n* Application objects will be deleted\r\n* DB-roles will be dropped\r\n* DB-views will be dropped\r\n* User-synonyms will be dropped");
if (answer==true) {
  document.getElementById('P10_APPLICATIONNAME').value = Name;
  doSubmit(Request);
}
}
Finally I have a page process to do the delete which fires when the request = delete

Is there a better way

Gus
Edited by: Gus C on Jan 24, 2013 1:43 AM

Edited by: Gus C on Jan 24, 2013 1:44 AM
  • 1. Re: Deleting From  A Tabular Form With A Dynamic Action
    VC Guru
    Currently Being Moderated
    Gus C wrote:
    Using Apex 4.2

    Is it possible to delete a row from a tabular form using dynamic actions.
    Yes, but why do you want to do that with a tabular form? do you need any more actions like ad new row,update.

    If not you don't need a tabular form instead you just need a sql report with a checkbox column to be able to delete via dynamic actions
    At the moment my report sql contains html and javasript for a delete button
    '<input type="button" name="Delete" value="Delete"  onclick="del(''delete'','''||a.applicationname||''')">' A2
    I then have javascript in my page header
    function del(Request, Name){
    var answer=confirm("Do you really want delete application "+Name+"?\r\n* Provider assignments will be deleted\r\n* Application objects will be deleted\r\n* DB-roles will be dropped\r\n* DB-views will be dropped\r\n* User-synonyms will be dropped");
    if (answer==true) {
    document.getElementById('P10_APPLICATIONNAME').value = Name;
    doSubmit(Request);
    }
    }
    How does this handle deleting multiple rows?
    Finally I have a page process to do the delete which fires when the request = delete

    Is there a better way
    Yes, because this doesn't look like its able to delete multiple rows. is that what you wanted?
  • 2. Re: Deleting From  A Tabular Form With A Dynamic Action
    Gus C Journeyer
    Currently Being Moderated
    No it should only delete one row at a time.
    Sorry this is a sql report, not a tabular form

    Gus
  • 3. Re: Deleting From  A Tabular Form With A Dynamic Action
    Joni Vandenberghe Pro
    Currently Being Moderated
    I would use an apex checkbox instead of letting the user type a name in the application.
    http://docs.oracle.com/cd/E14373_01/apirefs.32/e13369/apex_item.htm#CHDDCHAF

    As p_value parameter you can give the id of your item.

    In the submit process you put:
    FOR I in 1..APEX_APPLICATION.G_F01.COUNT LOOP
    DELETE FROM emp WHERE empno = to_number(APEX_APPLICATION.G_F01(i));
    END LOOP;

    Last you can add a PL/SQM validation that checks if only one checkbox is selected:
    IF APEX_APPLICATION.G_F01.COUNT-1=1 THEN
    RETURN NULL;
    ELSE
    RETURN 'Only one application can be selected';
    END IF;

    In my opinion this is the best way.
  • 4. Re: Deleting From  A Tabular Form With A Dynamic Action
    VC Guru
    Currently Being Moderated
    Gus C wrote:
    No it should only delete one row at a time.
    Sorry this is a sql report, not a tabular form
    It depends on lot more factors such as are there any page items/regions/process/computations dependent on this report data?, if yes then its best to submit the page.
    And use the built-in array to access the checked row instead of page item.

    If your answer is no then you may choose to use dynamic actions.
  • 5. Re: Deleting From  A Tabular Form With A Dynamic Action
    Gus C Journeyer
    Currently Being Moderated
    Nothing dependant.
    Can you give me an example of the DA

    gUS
  • 6. Re: Deleting From  A Tabular Form With A Dynamic Action
    VC Guru
    Currently Being Moderated
    Gus C wrote:
    Nothing dependant.
    Can you give me an example of the DA

    gUS
    First change the checkbox column to populate the value attribute with the a.applicationname column

    Create a new dynamic action as shown below

    Event : Click
    Selection Type : jQuery Selector
    jQuery Selector : :checkbox[name="f01"]
    replace f01 with the name of your checkbox column, you can find this by inspect element in firefox using firebug/chrome browser
    add a true action as Execute JavaScript Code with below code
    //set the page items value on client side
    $s('P10_APPLICATIONNAME',this.triggeringElement.value);
    Add another True action as Execute PL/SQL code and under code field add your plsql block to delete the record.
    //it should be something like
    delete from my_table where name = :P10_APPLICATIONNAME;
    Underneath that add your page item into Page items to submit field

    Hope this helps

    Cheers,
    Vikram
  • 7. Re: Deleting From  A Tabular Form With A Dynamic Action
    Gus C Journeyer
    Currently Being Moderated
    I think we are all getting a bit confused.
    This is a sql report, so there is no checkbox.

    I have a column in my report called ZZZ.
    In the sql
    a.applicationname ZZZ
    This is set as a report link going back to the same page and setting
    P10_APPLICATIONNAM to #ZZZ#

    I have a DA
    Event: Click
    Selection Type: JQuery Selector
    JQuery Selector: td[headers="ZZZ"] a

    True Action
    Seq: 5
    Action: Confirm
    Text: Do you really want delete application &P10_APPLICATIONNAME. ?
    Provider assignments will be deleted.
    Application objects will be deleted.
    DB-roles will be dropped.
    DB-views will be dropped\r\n* User-synonyms will be dropped
    Seq: 10
    Action: Execute Javascript Code
    $s('P10_APPLICATIONNAME',this.triggeringElement.value);
    Seq: 20
    Action: Execute PL/SQL Code
    BEGIN
    p_dwh_obs_apx.pr_10_delete_application(:P10_APPLICATIONNAME
                                         ,:APP_USER
                                         ,:P10_OUTPUT
                                          );
    END;
    Page Items To Submit: P10_APPLICATIONNAME

    When I click on the ZZZ link, the confirm pops up, but when I press ok,
    nothing happens.

    Also, when I click on another link then my pop up message displays the value the the last link.

    Ideally I would like to use a button, instead of a report link

    I hope this is clear

    Thanks again

    Gus

    Edited by: Gus C on Jan 24, 2013 11:08 PM

    Edited by: Gus C on Jan 24, 2013 11:10 PM
  • 8. Re: Deleting From  A Tabular Form With A Dynamic Action
    Gus C Journeyer
    Currently Being Moderated
    I have it sort of working now by following this example


    [http://apex.oracle.com/pls/otn/f?p=39830:LOGIN:7057477765267]

    What I cannot get working is;
    I need to display the value of P10_APPLICATIONNAME in the confirmation message

    My rep col ZZZ has a link text of
    <img src="#IMAGE_PREFIX#del.gif" alt="Delete Application #APPLICATIONNAME#">
    Link Attributes
    id="#ZZZ#" class="delete"
    Target URL
    URL: #

    My DA is
    Event: Click
    Selection Type: JQuery Selector
    JQuery Selector: a.delete

    True Actions
    Seq5
    Action: Set Value
    Set Type: Javascript Expression
    this.triggeringElement.id;
    Selection Type: Item
    Item: P10_APPLICATIONNAME

    True Action
    Seq: 10
    Action: Confirm
    Text: Do you really want delete application &P10_APPLICATIONNAME. ?
    Provider assignments will be deleted.
    Application objects will be deleted.
    DB-roles will be dropped.
    DB-views will be dropped\r\n* User-synonyms will be dropped
    Seq 15
    Action: Submit Page
    Request: delete

    Seq 20
    Action: Refresh
    Selection Type: Region
    Region: Applications

    Seq 25
    Action: Cancel Event

    I also have a page process to do the delete which has a condition
    Request=Exp1
    Exp1 is delete.

    The whole process works, but I just cannot get the value of P10_APPLICATIONNAME
    to display in the confirmation message

    Cheers

    Gus

    Edited by: Gus C on Jan 25, 2013 1:02 AM
  • 9. Re: Deleting From  A Tabular Form With A Dynamic Action
    VC Guru
    Currently Being Moderated
    Amend your report column link to include custom attribute like appname="'||a.application_name||'"

    and in message try this.triggeringElement.appname
  • 10. Re: Deleting From  A Tabular Form With A Dynamic Action
    Gus C Journeyer
    Currently Being Moderated
    I have altered my columns linked text to be
    <img src="#IMAGE_PREFIX#del.gif" alt="Delete Application #APPLICATIONNAME#" appname="'||a.applicationname||'">
    And my message to be
    Do you really want delete application this.triggeringElement.appname ?
    Provider assignments will be deleted.
    Application objects will be deleted.
    DB-roles will be dropped.
    DB-views will be dropped\r\n* User-synonyms will be dropped
    Still not working
    Do I need to put something around this.triggeringElement.appname ?

    Gus
  • 11. Re: Deleting From  A Tabular Form With A Dynamic Action
    Tom Petrus Expert
    Currently Being Moderated
    Since you defined the dynamic action jQuery selector to be "a.delete", your triggeringElement will be the anchor tag, and not the image. Put the appname attribute on the anchor tag, or get it from the image element
    $("img", this.triggeringElement).attr("appname")
    I'd also argue that this would be a good example to use a "data-" attribute instead of defining a custom attribute. Instead of defined "appname", define "data-appname". You can then retrieve the data with jQuery .data():
    $("img", this.triggeringElement).data("appname")
    (or
    $(this.triggeringElement).data("appname")
    when putting it on the anchor)
  • 12. Re: Deleting From  A Tabular Form With A Dynamic Action
    Gus C Journeyer
    Currently Being Moderated
    ok, totally confused now.
    Can you please explain what goes where.
    What goes in the report link and what goes in the DA

    Thanks

    Gus
  • 13. Re: Deleting From  A Tabular Form With A Dynamic Action
    Tom Petrus Expert
    Currently Being Moderated
    For starters, try to replace
    this.triggeringElement.appname
    in your message with
    $("img", this.triggeringElement).attr("appname")
    and see what that gives.
  • 14. Re: Deleting From  A Tabular Form With A Dynamic Action
    Gus C Journeyer
    Currently Being Moderated
    I have put
    $("img", this.triggeringElement).attr("appname")
    in my message.
    So the code for the message is
    Do you really want delete application $("img", this.triggeringElement).attr("appname") ?
    Provider assignments will be deleted.
    Application objects will be deleted.
    DB-roles will be dropped.
    DB-views will be dropped\r\n* User-synonyms will be dropped
    No value is substituted. The message just appears as above

    Gus
1 2 Previous Next

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points