user1358852
user1358852

Reputation:

XPages - querysavedocument event

I'm working with the XPages querysavedocument event for the first time and am trying to stop the XPage from being saved. I've tried

return false;

but this does not stop the document from being saved. What is the correct syntax to stop the XPage from being saved?

The code which saves the document is:

<xp:this.action>
<xp:saveDocument var="document1"></xp:saveDocument>
</xp:this.action>

This is the same as in Knut's answer below. The code which I have in the querySaveDocument is

var choice:boolean = false;

for (var k = 1; k < 7; k++) {
    choice = false;
    sectionname = "C1B"+k;
    for (var n = 1; n < 7; n++) {
        fieldname = "C1B"+k+"_R"+n;

        if (getComponent(fieldname).getValue() != ""){
            choice = true; 
            break;};
    }

    if (choice == false){
        viewScope.put("EmptyRadioField",sectionname);
        var comp = getComponent("RadioButtonValidationDialog");
        comp.show();
        return false;
    }
}

The dialog box is shown correctly when choice == false but the XPage is saved nonetheless.

I have solved my problem by moving the validation to csjs:

for (var k = 1; k < 7; k++) {

choice = false;
sectionname = "C1B"+k;

for (var n = 1; n < 7; n++) {
fieldname = "C1B"+k+"_R"+n;

var id = "view:_id1:_id2:_id3:"+fieldname;
fieldvalue = dijit.byId(id).getValue();

if (fieldvalue != false){
choice = true; 
break;};

}

if (choice == false){

sectionid = "view:_id1:_id2:_id3:lbl"+sectionname;
sectionvalue = dojo.byId(sectionid).innerHTML;
alert("Please enter a value for " + sectionvalue);
return false;

}
}   

This works well, despite a lot of trying I just couldn't get it working in SSJS.

Upvotes: 1

Views: 1434

Answers (1)

Knut Herrmann
Knut Herrmann

Reputation: 30970

return false; is right.

Maybe, the event querySaveDocument does not get executed at all. That happens e.g. if you save the document in SSJS with document1.save().

You have to have a save action like

  <xp:this.action>
     <xp:saveDocument var="document1"></xp:saveDocument>
  </xp:this.action>

or to use

<xp:eventHandler
    event="onclick"
    submit="true"
    refreshMode="complete"
    immediate="false"
    save="true">
</xp:eventHandler>

Upvotes: 1

Related Questions