This discussion is archived
13 Replies Latest reply: Sep 4, 2012 3:51 AM by Prabodh RSS

in tabular form, is there a way to select one row as the default row?

517508 Newbie
Currently Being Moderated
Hi, I have a tabular form which lists the many addresses that a fisherman may have. The query is: select default_addr_flag, addr1, addr2, city, state, zip from addresses where fisher_id = :PXX_fisher_id.

I would like to have them set the default_addr_flag = 'Y' for ONLY ONE record....so even if they have many addresses, one must be selected as the default for any correspondence.

Are there any examples, or does anyone have a suggestion. thank you!

karen
  • 1. Re: in tabular form, is there a way to select one row as the default row?
    Mehabub Sheikh Journeyer
    Currently Being Moderated
    You have to put them into collection and then check individual record from the collection to see that default flag has been set.
    If not throw a error message to user.

    Thanks,
    Mehabub
  • 2. Re: in tabular form, is there a way to select one row as the default row?
    517508 Newbie
    Currently Being Moderated
    thanks for your help. Is there anyway to do this without collections? I wonder if I could check the processing within the db. thanks again.
  • 3. Re: in tabular form, is there a way to select one row as the default row?
    Mehabub Sheikh Journeyer
    Currently Being Moderated
    Tabular form data are not posted to DB until and unless the page is submitted.
    In between you have to do with apex collections only because tabular form data are stored in apex collections itself.

    Thanks,
    Mehabub

    Edited by: Mehabub Sheikh on Aug 17, 2012 8:24 AM
  • 4. Re: in tabular form, is there a way to select one row as the default row?
    517508 Newbie
    Currently Being Moderated
    so, a dynamic action could not be used?

    sorry to be so obstinate. I just reworked many of my pages to eliminate collections as they were becoming quite complicated and posed huge issues when we had to debug. thanks
  • 5. Re: in tabular form, is there a way to select one row as the default row?
    Hari_639 Guru
    Currently Being Moderated
    Hello Karen,

    You can do it with-out using collections.

    Make default_addr_flag as check-box item.

    Add onClick event and call JS function
    onClick="javascript:resetOthers(this);"
    In JS function, check if already any other check box is selected, if so un-check them. Put following code under JS section
    <script>
    function resetOthers(pThis)
    {
    $("input[name="+$(pThis).attr("name")+"]:checked").attr("checked",false);
    $(pThis).attr("checked",true);
    }
    </script>
    Remove Pagination for Tabular Form and set rows displayed to high value. (hope there won;t be much number of addresses for a fisher man) So all addresses are dsiplayed in on go.

    Regards,
    Hari

    Please note that above is not tested and I assume you are using APEX 4.0 or later Otherwise please include jQuery lib
  • 6. Re: in tabular form, is there a way to select one row as the default row?
    517508 Newbie
    Currently Being Moderated
    thank you! yes, I am using version 4.1. I am not familiar with on-click event...is that in the attribute region of the default_flag? or is it a dynamic action? thanks
    again. Karen

    ps. this is a tabular form, so if this is a dynamic action, is there a way to specify the column of a report?

    Edited by: KEH813 on Aug 17, 2012 2:50 PM
  • 7. Re: in tabular form, is there a way to select one row as the default row?
    953771 Explorer
    Currently Being Moderated
    Dear Karen,

    another aspect:

    If you really need to be sure that each fisher has only one default adress you should implement that on database level.
    Client side evaluation does for example not work when the current default adress is not displayed which might be the case when you use pagination.

    You might implement a server side "constraint" by using a functional index.

    Example:
    create unique index only_one_def_adr_per_fisher on adresses
    (
      case when default_addr_flag = 'Y' then fisher_id end
    );
    Greetings
    Marc
  • 8. Re: in tabular form, is there a way to select one row as the default row?
    Hari_639 Guru
    Currently Being Moderated
    Its not dynamic action.

    In tabular form, go to column attributes of "default_addr_flag" column.

    Set "Display As" -> Simple Checkbox
    "Element Attributes" -> onClick="javascript:resetOthers(this);"

    Next Edit page and Put following code under "JavaScript" section.
    function resetOthers(pThis)
    {
    $("input[name="+$(pThis).attr("name")+"]:checked").attr("checked",false);
    $(pThis).attr("checked",true);
    }
    Remove Pagination for Tabular Form and set rows displayed to high value. That should do the trick.

    Regards,
    Hari
  • 9. Re: in tabular form, is there a way to select one row as the default row?
    517508 Newbie
    Currently Being Moderated
    Hi Hari, sorry for the delay in responding. I have done as suggested, but included the javascript as follows for page javascript...not certain if that was needed or not.

    <script language="JavaScript" type="text/javascript">

    function resetOthers(pThis)
    {
    $("input[name="+$(pThis).attr("name")+"]:checked").attr("checked",false);
    $(pThis).attr("checked",true);
    }




    </script>


    I have removed pagination and placed the element attribute as directed. I am able to check the box, but the value is no saved. The value for default_addr_flag should be 'Y' for true or 'N' for false. I am wondering if Y/N should be substituted for TRUE/FALSE in the javascript?

    thanks again, Karen
  • 10. Re: in tabular form, is there a way to select one row as the default row?
    Prabodh Guru
    Currently Being Moderated
    Hi Karen,
    I think first of all you should get yourself a browser and add-ons that allow you to inspect the HTML DOM elements. E.g. FF/Firebug/Error Console. Once you have the required tools you will be able to see for yourself what the DOM has, and then work out what you need to do.
    Most members, including myself, at times post solutions without really trying them out as they appear to be "obvious" even when they are not.

    Taking forward from the point where you have made the default address indication a "simple checkbox" from the Report Attributes tab, if you inspect the checkbox element you will find that it is somewhat more complex and Apex has created the elements with some JS code. E.g. this is a snippet from one of my application pages.
    <td headers="IS_CUSTOMER">
     <label class="hideMeButHearMe" for="f08_0001">Is Customer</label>
     <input type="checkbox" onclick="if (this.checked) {apex.jQuery('#f08_0001').val('Y');} else {apex.jQuery('#f08_0001').val('');}" id="f08_0001_01" checked="checked" value="Y" name="f08_NOSUBMIT" autocomplete="off">
     <input type="hidden" id="f08_0001" value="Y" name="f08" autocomplete="off">
    </td>
    You will see that
    a.Apex has created a onclick event trigger
    b. If sets the value of Unchecked checkbox to null ("").
    c. In my page the checkbox maps to f08, you need to see which item it maps to in your page.
    d. The id of the rendered checkbox is id of hidden element + _01.

    The consequence of this is that if you define a onclick trigger in the Element attributes it overrides and suppresses Apex from inserting its own JS code!

    To be able to uncheck all checkboxes other than the one the user has currently checked you will need to do this:
    i. In the Column's Element Attributes field write
    onclick="doDftAddr(this);"
    You could name the function the way you want it, this is an example.
    ii.In the Page HTML Header write
    <script type="text/javascript">
    function doDftAddr(pThis) {
      va = pThis.id.split("_");
      var vb = va[0]+'_'+va[1];
     if (pThis.checked) {
        vy = 'input:checked[id^="'+va[0]+'_"]'
        $("["+vy+"]").attr("checked",false);
        apex.jQuery("["+vy+"]").val('N');
        apex.jQuery('['+'input:hidden[id^="'+va[0]+'"_]'+']').val('N');
        apex.jQuery('#'+pThis.id).attr("checked",true);
        apex.jQuery('#'+pThis.id).val("Y");
        apex.jQuery('#'+vb).val('Y');
       } else {
        apex.jQuery('#'+vb).val('N');
       }
    }
    </script>
    Cheers,
  • 11. Re: in tabular form, is there a way to select one row as the default row?
    517508 Newbie
    Currently Being Moderated
    thanks for your help! I appreciate it. I have found something that will allow me to view the html. css, etc code generated behind my apex app...of course, I am new to javascript and so not quite certain what exactly to be looking for. I have implemented your suggestion of onclick="doDftAddr(this);" and the html header javascript is in place... as before, when I click on the default address box for a row in my tabular form, it clears out any check in a past selected default address.

    The problem is when I hit SAVE, it just hangs up...nothing happens. Using the earlier example that Hari provided closes the window after SAVE, but the default_address_flag remains null. Again, any suggestion would be great...and/or also what I should look for, or can provide to you, that might help debug.

    thanks again, Karen
  • 12. Re: in tabular form, is there a way to select one row as the default row?
    841711 Newbie
    Currently Being Moderated
    KEH813 wrote:
    ...
    The problem is when I hit SAVE, it just hangs up...nothing happens
    ...
    Hi,

    If I try the solution of Prabodh I get this strange error message in Firebug (in German, sorry) on 'SAVE'.

    Die Zeichenkodierung des Reintext-Dokuments wurde nicht deklariert. Das Dokument wird in manchen Browser-Konfigurationen mit verstümmeltem Text dargestellt, wenn das Dokument Zeichen außerhalb des US-ASCII-Bereichs enthält. Die Zeichenkodierung der Seite muss im Transferprotokoll deklariert werden oder die Datei muss eine Byte-Order-Markierung als Kodierungssignatur verwenden.

    Google translate says:

    The character encoding of the plain text document was not declared. The document is in some browser configurations shown with garbled text when the document contains characters outside the US-ASCII range. The encoding of the page must be declared in the transfer protocol, or use the file must be a Byte Order Mark as encoding signature

    I assume that there is some strange character in the html, or an error with the quotes, but I can't verify it!

    Thx
    Steffen

    Edited by: Steffen Clauss on 04.09.2012 10:59
  • 13. Re: in tabular form, is there a way to select one row as the default row?
    Prabodh Guru
    Currently Being Moderated
    Hi,

    There was an issue with code posted earlier. It was causing the Submit to error out.

    Here is the corrected code
    <script type="text/javascript">
    function doDftAddr(pThis) {
      va = pThis.id.split("_");
      var vb = va[0]+'_'+va[1];
     if (pThis.checked) {
        vy = 'input:checked[id^="'+va[0]+'_"]'
        $("["+vy+"]").attr("checked",false)
        apex.jQuery('#'+pThis.id).attr("checked",true);
        apex.jQuery("'"+'[input:hidden[name="'+va[0]+'"][value="Y"]]'+"'").val("");
        apex.jQuery('#'+vb).val('Y');
       } else {
        apex.jQuery('#'+vb).val('N');
       }
    }
    </script>
    Note: The SimpleCheckbox accepts only Y and null. I have not been able to make it work with Y and N values.
    Cheers,

Legend

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