Guten Morgen,
ich sitze jetzt seit Tagen an folgendem Problem:
Ich habe auf einer XPage einen FileUpload Control und möchte über dessen Validation verhindern, dass mehr als ein Dokument angehängt wird. Leider funktioniert bei mir die SSJS-Validation in diesem Zusammenhang nicht....
Ich habe das Ganze mal auf einer Text-XPage nachgebaut:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
<xp:dominoDocument var="document1" formName="Test"></xp:dominoDocument>
</xp:this.data>
<xp:fileUpload id="fileUpload"
value="#{document1.PDFAnhangRT}" style="margin-top:5px;height:29px"
disableClientSideValidation="true" disableValidators="false" required="true">
<xp:this.validators>
<xp:validateExpression message="FEHLER">
<xp:this.expression><![CDATA[#{javascript: if(!document1.getAttachmentList("PDFAnhangRT").isEmpty())
{
return false;
}
else
{
return true;
}
}]]></xp:this.expression>
</xp:validateExpression>
</xp:this.validators>
<xp:eventHandler event="onchange" submit="true"
refreshMode="complete" disableValidators="true">
<xp:this.action><![CDATA[#{javascript://}]]></xp:this.action>
</xp:eventHandler>
</xp:fileUpload>
<xp:message id="message1" for="fileUpload1"></xp:message>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:fileDownload rows="30" id="fileDownloadPDFAnhängen"
displayLastModified="false" style="float:right" allowDelete="true"
hideWhen="true" value="#{document1.PDFAnhangRT}" displayType="true">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete" disableValidators="true">
</xp:eventHandler>
</xp:fileDownload>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button id="button1" value="Submit">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete" immediate="false" save="true"></xp:eventHandler>
</xp:button>
</xp:view>
Kann es sein, dass in diesem Zusammenhang nur eine CSJS-Validation funktioniert?
Gruß
Matthias
Das funktioniert schon.... allerdings erst beim Speichern der 2. Datei.
Dann muss man dem Benutzer auch die Möglichkeit bieten die evtl. fehlerhaft angehöngte Datei zu entfernen.
Ich habe es auch schon einmal so gemacht, dass das upload-control verborgen wird wenn eine bestimmte Anzahl von Anhängen überschritten wird. D.h. das Control wird erst wieder sichtbar wenn ein Attachment entfernt wird.
P.S: hatte das automatische Speichern übersehen. Hier mal mein Code:
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core">
<xp:this.data>
<xp:dominoDocument var="document1" formName="Test"></xp:dominoDocument>
</xp:this.data>
<xp:fileUpload id="fileUpload1" value="#{document1.PDFAnhangRT}"
disableValidators="false">
<xp:this.validators>
<xp:validateExpression message="Fehler">
<xp:this.expression><![CDATA[#{javascript:if(!document1.getAttachmentList("PDFAnhangRT").isEmpty())
{
return false;
}
else
{
return true;
}}]]></xp:this.expression>
</xp:validateExpression>
</xp:this.validators>
</xp:fileUpload>
<xp:br></xp:br>
<xp:message id="message1" for="fileUpload1"></xp:message>
<xp:fileDownload rows="30" id="fileDownload1"
displayLastModified="false" value="#{document1.PDFAnhangRT}"
allowDelete="true">
</xp:fileDownload>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button value="Speichern" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action>
<xp:saveDocument></xp:saveDocument>
</xp:this.action>
</xp:eventHandler>
</xp:button>
</xp:view>
wenn Du auf CSJS stehst geht auch soetwas.
<xp:this.data>
<xp:dominoDocument var="document1" formName="Test"></xp:dominoDocument>
</xp:this.data>
<xp:fileUpload id="fileUpload1" value="#{document1.PDFAnhangRT}"
disableValidators="false">
<xp:this.validators>
<xp:validateExpression message="Fehler">
<xp:this.expression><![CDATA[#{javascript:if(!document1.getAttachmentList("PDFAnhangRT").isEmpty())
{
return false;
}
else
{
return true;
}}]]></xp:this.expression>
</xp:validateExpression>
</xp:this.validators>
<xp:eventHandler event="onchange" submit="true"
refreshMode="complete">
<xp:this.script><![CDATA[if("#{javascript:document1.getAttachmentList("PDFAnhangRT").isEmpty()== true}"){
console.log("#{javascript:document1.getAttachmentList("PDFAnhangRT").isEmpty()}");
return true;
}else{
console.log("nicht Leer")
return false;
}]]></xp:this.script>
</xp:eventHandler></xp:fileUpload>
<xp:br></xp:br>
<xp:message id="message1" for="fileUpload1"></xp:message>
<xp:fileDownload rows="30" id="fileDownload1"
displayLastModified="false" value="#{document1.PDFAnhangRT}"
allowDelete="true">
</xp:fileDownload>
<xp:br></xp:br>
<xp:br></xp:br>
<xp:button value="Speichern" id="button1">
<xp:eventHandler event="onclick" submit="true"
refreshMode="complete">
<xp:this.action>
<xp:saveDocument></xp:saveDocument>
</xp:this.action>
</xp:eventHandler>
</xp:button>