ChrisCarlson Posted December 1, 2015 Report Share Posted December 1, 2015 I am looking for a way to check if file attachment fields are blank at time of submit. I have 8 file attachment fields and I want to display a message if any of the 8 are blank. Allow the user to confirm (OK - proceed with submit) or cancel (Cancel - allow user to complete fields prior to submit). I would normally user required field setting however the fields are optional and the message would be FYI only. This also becomes an issue when page reloads and drops the file attachments where remaining fields are intact, and user does not notice attachment fields are blank on final submit. Quote Link to comment Share on other sites More sharing options...
Xiang Posted December 5, 2015 Report Share Posted December 5, 2015 Hi ccarls3, How are you doing? I've wrote a simple script: if an image field is empty, the error message is displayed. When a user clicks the second time, the record is added. You can add as many fields as you want. <SCRIPT LANGUAGE="JavaScript"> var first_time = true; function check_images() { var image1 = document.getElementById("InsertRecordfile1").value; var image2 = document.getElementById("InsertRecordfile2").value; var image3 = document.getElementById("InsertRecordfile3").value; var emptyFields = false; if (image1.length < 1) emptyFields = true; if (image2.length < 1) emptyFields = true; if (image3.length < 1) emptyFields = true; if ( emptyFields) { if (first_time) { first_time = false; alert("Image field is empty. If you want to continue, please click Submit again"); return false; } } } document.getElementById("caspioform").onsubmit=check_images; </SCRIPT> If you want a pop-up window, I'll try writing a new code Have a nice day! Quote Link to comment Share on other sites More sharing options...
ChrisCarlson Posted December 5, 2015 Author Report Share Posted December 5, 2015 Xiang, I tried this script in the footer and it did not work. I am using a datapage update (reports details). I changed fields from InsertRecord to EditRecord and it still did not work. I tried moving script to header as well. Quote Link to comment Share on other sites More sharing options...
Xiang Posted December 5, 2015 Report Share Posted December 5, 2015 It's interesting! I just check on the Details page, code works. Could you verify: "file1", "file2", "file3" are changed to the names of your fields; These fields are editable; the code is entered to the Footer of the DataPage (not the webpage) and the "Source" button is clicked. Could you send a URL? Quote Link to comment Share on other sites More sharing options...
ChrisCarlson Posted December 7, 2015 Author Report Share Posted December 7, 2015 I placed the following script in my footer but it does not work, This is on an update datapage. Is the onsubmit correct? <SCRIPT LANGUAGE="JavaScript"> var first_time = true; function check_images() { var image1 = document.getElementById("EditRecordPhoto_Attachment1_File").value; var image2 = document.getElementById("EditRecordPhoto_Attachment2_File").value; var image3 = document.getElementById("EditRecordPhoto_Attachment3_File").value; var emptyFields = false; if (image1.length < 1) emptyFields = true; if (image2.length < 1) emptyFields = true; if (image3.length < 1) emptyFields = true; if ( emptyFields) { if (first_time) { first_time = false; alert("Image field is empty. If you want to continue, please click Submit again"); return false; } } } document.getElementById("caspioform").onsubmit=check_images; </SCRIPT> Quote Link to comment Share on other sites More sharing options...
Aurora Posted December 7, 2015 Report Share Posted December 7, 2015 Hello Christopher and Xiang. Why don't you just make all file fields required ? It would be easy I believe . Aurora Quote Link to comment Share on other sites More sharing options...
ChrisCarlson Posted December 8, 2015 Author Report Share Posted December 8, 2015 The image files are not all required. We have 8 upload files for photos but sometimes user may only use 1 or 2. Quote Link to comment Share on other sites More sharing options...
cheonsa Posted September 19 Report Share Posted September 19 Hi all, I just wanted to share another solution to display a message if one of the file fields is blank. Instead of using a script, you can use a Calculated Value. Here is the sample formula: CASE WHEN (LEN(CAST([@field:File1] AS NVARCHAR(125))) = 0 OR [@field:File1] IS NULL) OR (LEN(CAST([@field:File2] AS NVARCHAR(125))) = 0 OR [@field:File2] IS NULL) OR (LEN(CAST([@field:File3] AS NVARCHAR(125))) = 0 OR [@field:File3] IS NULL) THEN 'No file attachment in one of the file fields' ELSE '' END Hope this helps. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.