Xpages button validation - xpages

I am using the multiple uploader from openntf. I want to add an error message if the user has selected the files but not uploaded them.
I am thinking about some kind of "must click" button, and if the user is not uploading the files, it should give a message while saving the document saying: "Attachments are not uploaded. Do you want to continue?"
How can I check if the span tag : ynFileUploadInfo contains something or not? And depending on that, trigger the validation.

Add following client side JavaScript (CSJS) code to your save button:
var files = document.getElementById('ynFileUploadMulti').files;
if (files && files.length > 0) {
if ( ! confirm('Attachments are not uploaded. Do you want to continue?')) {
return false;
}
}
return true;
It will ask the user if listed (additional) attachments really don't have to be uploaded.
If user clicks "OK" then document will be saved without the listed attachments.
If user clicks "Cancel" then document won't be saved and user can click "Upload now" to upload the listed attachments.
Remark: if CSJS code returns false in an event then submit and server side JavaScript (SCJS) code won't get executed.

Related

Prevent primefaces uploaded file from disappearing when it completes uploading

I would like to implement a multiple fileUpload.
I don't want the upload and the cancel buttons to be appearing on screen,so basically there are two ways for me to proceed.
First way : Hiding the Upload and the Cancel buttons via CSS.
I can hide them,the problem is that I can't trigger anymore the upload button,so files will never be uploaded.
In this case : is there a way to trigger the Upload button with a commandbutton ?
Second Way : adding auto="true" to the fileupload tag ,so the Upload and Cancel Buttons would disappear,but the problem with this way is that when the file is uploaded,it instantly disappears from screen,and the user can't no more click on the cancel icon next to the progress bar to cancel the upload.
So,in this case,is it possible to prevent the uploaded file from disappearing when the file is uploaded ?
I would like it to work like the google uploading file system when sending a mail , the user can choose to upload many files,but can still delete those if he chooses to (before sending the mail of course).
You can activate p:fileUpload's buttons from your own buttons like:
<p:commandButton value="My upload button" onclick="$('.ui-fileupload-upload').click(); return false;" />
The 3 buttons use the css classes
.ui-fileupload-choose
.ui-fileupload-cancel
.ui-fileupload-upload
Hide them with for example
.ui-fileupload-upload {
display: none;
}

File validation on XPages

I am working on application in XPages and I need to do file upload validation on the server side.
I read that file upload only works on client side, so I tried to validate another filed that stores file name attached. I did it on the on change event of the file upload. The problem occurs when I delete an attached file- there is no on change event on file download control… any suggestions? Or maybe different way?
Thanks
Unsaved list of attachments can be accessed from the getAttachmentList("RTFieldName") method of the data source.
I suggest using a hidden input and custom validator to have more control, like:
<xp:message
id="message1"
for="inputHidden1"></xp:message>
<xp:br></xp:br>
<xp:inputHidden
id="inputHidden1"
value="arbitrary">
<xp:this.validators>
<xp:customValidator>
<xp:this.validate><![CDATA[{javascript:
// RTField the name of the rich text field that holds attachments
if(document1.getAttachmentList("RTField").size()==0) {
// You might want to do more checks here.
var inputHidden1 = getComponent("inputHidden1");
inputHidden1.setValid(false);
return "You have to upload a file!" // your error message
}}]]></xp:this.validate>
</xp:customValidator>
</xp:this.validators>
</xp:inputHidden>
Remember, value="arbitrary" is important. Empty fields will not trigger custom validators.

xpages: compute Confirm Action confirmation text does not work in XPiNC

I'm using Notes/Domino 8.5.3. I've added a button control to an xpage. The button uses a Confirm Action to display a client-side prompt to the user before continuing with the next action defined for the button. When I use static text for the Confirmation Text for the Confirm Action, the confirmation prompt is displayed. However, when I change the Confirmation Text to be computed, and retrieve the text from a profile document, the confirmation prompt it not displayed at all in XPiNC. The confirmation prompt with the computed confirmation text is displayed just fine in a browser. Is there a work-around for this issue with XPiNC?
Following is the code I'm using in the Confirm Action to get the text for the prompt:
var server = database.getServer();
var dbProfile:NotesDocument = database.getProfileDocument("DBProfile", "");
var msg = dbProfile.getItemValueString("ContactsInitUpdatePrompt");
return msg;
To further my comments, this is a work around I use the below code for an app that uses the bootstrap extension library on the web but uses basic functionality with xpinc.
If the values for xPinc are different you could make the confirm action different in the browser and in the client.
if (#ClientType()== "Notes")
{
<action>;
}
else{
<action>;
}
I think that profile documents are a bad idea in xPages though. Having to restart HTTP to get a new value ruins the point I think. Almost better to hard code values at that point. I think you can set application scope to handle the work of profile documents. But then application scope in xpinc is just on the current machine as the server is the client.

FB.ui - Send dialog reappears after submitting

We're seeing some strange behavior with Facebook Send dialogs (Javascript SDK, FB.ui method). After the Send button is clicked, the dialog disappears, then reappears. The dialog does disappear after a while without any user action, but this delay varies (anywhere from a split second to several seconds).
The messages are delivered without problems.
How to reproduce:
https://apps.facebook.com/barclays_pingit/
Click on "Send Message" under the "Tell a friend" title
Add a recipient and message
Click "Send"
Or:
Click on "Make your own video"
Choose a friend, how much they owe you, and for what
Click "Make video"
You can skip to the end of the video, then click "Send video to ..."
Add a message Click "Send"
Does anyone have any ideas?
Sorry I can't give you the answer, but as I have the same problem, here is a quick patch:
var callback = function callback(response) {
var clear_callback = function(){
$('.fb_dialog').remove();
};
var arr = [250,1000,2000,3000,4000,5000,7000];
for (var i in arr)
{
setTimeout(clear_callback,arr[i]);
}
}
FB.ui(obj, callback);

Confirmation dialog for Cancel button in sharepoint webpart

hi i am creating a webpart. i have a custom toolpart for my webpart. there i'll type some text. when i click save it will print in sharepointpage. when an user click cancel in webpart's toolpart i need to ask confirmation dialog and if the user selects "OK" i need to run some server side code. is it possible. Please help me on that.
In your toolpart register an onsubmit event handler (this will be called on OK/Apply/Cancel or if you do anything else that causes a postback)
protected override void OnPreRender(EventArgs e)
{
// Don't run if in SharePoint Designer
if (ParentToolPane.InCustomToolPane)
return;
// Connect to the form Submit event RenderToolPart event is too late,
// Putting this in OnLoad event causes javascript error webpart may
// be loaded for ApplyChanges but not rendered - leading to javascript error
this.Page.RegisterOnSubmitStatement("submit", "yourCustom_onSubmit();");
base.OnLoad(e);
}
Also be sure to have a javascript function yourCustom_onSubmit on your page - putting up a confirmation message and cancelling submit is up to you.
Yes you can. It's like asp.net, so you can insert a Javascript, like the sample we found at this site.

Resources