1

I have an xpage with a data view control, that has show checkbox and show header checkbox enabled. I want to be able to provide confirmation with a count of selected documents to the user when they click the submit button.

Example "Are you sure you want to submit x number of documents?"

My confirm action returns 0 regardless of how many documents I select. What am I doing wrong?

<xp:confirm>
<xp:this.message><![CDATA[#{javascript:var dataView1:com.ibm.xsp.extlib.component.data.UIDataView = getComponent("dataView1");
var val = dataView1.getSelectedIds();
var len = val.length;
return "Are you sure you want to submit " + len +  " number of documents?";
}]]></xp:this.message>
</xp:confirm>
C. Lackey
  • 98
  • 4

1 Answers1

1

The immediate problem that you're running into is that the confirmation message is most likely being computed as the button is rendered the first time - which is to say, when no documents are checked.

Even beyond that, though, the getSelectedIds method is tricky: the selected documents are cleared after each request, so something that would do a request to the server to get the selected ID count would also have the side effect of clearing out the selections.

What may be the way to do here is to do the check client-side with something like this:

<xp:eventHandler ...>
    <!-- other action stuff here -->

    <xp:this.script><![CDATA[
        var count = dojo.query("tbody input[type='checkbox']:checked", dojo.byId("#{id:yourDataViewId}")).length;
        return XSP.confirm("Are you sure you want to submit " + count + " document" + (count == 1 ? "" : "s") + "?");
    ]]></xp:this.script>
</xp:eventHandler>

The Dojo query in there will search for all checked checkboxes inside the body part of the data view (to exclude the header checkbox), restricted to within the specific data view you want to search for. The XSP.confirm client-side method is the same idea as the <xp:confirm/> simple action, and returning the value from it will cancel the submit if the user says no.

Jesse Gallagher
  • 4,461
  • 13
  • 11
  • Thank you Jesse for taking time out to answer my question. That worked for me! Trying to figure out when to use what is challenging. – C. Lackey Sep 16 '15 at 17:21