We help IT Professionals succeed at work.

Livecycle Event PreSubmit

contesa
contesa asked
on
2,215 Views
Last Modified: 2012-05-09
I have a form with a Submit button and one mandatory field that has code to validate format of date and to keep focus on field until correct format is entered.

If the user clicks on the Submit button without clicking in the Date Field first, the form is sent.  I want to insert a presubmit event that will check the mandatory field prior to sending the form.

I used the following code but after it alerts the user that data is missing, i get an error that says Submit Cancelled and the form is not sent.  I am using an Email Submit button - nothing in the url field and PDF selected.

I would also like to add a subject line and body to message prior to sending.

//Check if all the mandatory fields are filled in or not
if(isMandatoryFieldMissed.value == "0"){
this.resolveNode("#event").submit.target = "mailto:dice@njdge.org";

}
else{
xfa.host.messageBox("One or more of the required fields were missing data before submitting.");        
}


Comment
Watch Question

Umar Topia.Net Full Stack Developer
CERTIFIED EXPERT

Commented:
Create one javascript function that checks whether the user has entered the value or not.

and assign that javascript function to the "OnClientClick" property of your submit button.

i.e.:

btn1.OnClientClick = "return CheckValidation();";


function CheckValidation()
{
if(condition false)
{
return false;
}

}


Author

Commented:
The click event is not available for the Submit button.

Author

Commented:
Changed Submit button to Regular and Click event was available.

Added the following code:
function ValidateForm(form)
{
   if(IsEmpty(DICE.CEB_DICE_INCIDENTS.REPORT_DATE))
   {
      alert('You have not entered a DATE SUBMITTED')
      DICE.CEB_DICE_INCIDENTS.REPORT_DATE.focus();
      return false;
   }
 
 
return true;
 
}

I am able to click Submit without any alert.  What am I missing?

I also have this on the mousedown event for the Submit button.

event.target.submitForm({cURL:"mailto:dice@njdge.org?subject=D.I.C.E. Submission Form&body=D.I.C.E. Submission Form attached.",cSubmitAs:"PDF",cCharset:"utf-8"});
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You may set the button readOnly on initialize event and when the Date is set, change it back to open
this.access = "readOnly";

Open in new window

Author

Commented:
Hi Genius,

How would I change it back to Open when Date is set?

I am a beginner programmer... just need a sample and I will tweak it as necessary.

Thanks for all of your help.
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
Set the change* event of the Date with : Send_by_mail1.access = "" where Send_by_mail1 is the name of your button
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
If you need more help, please post your document.
1. IsEmpty method is available in VBScript. I hope you are uing JavaScript by default. So IsEmpty is unrecognized method. So to find whether value exists or not, just check 'value' property of the textbox object. Sample iss:
var dateValue = document.getElementById('REPORT_DATE').value

Make sure you are accessing correct object and the object exits i.e, you have used DICE.CEB_DICE_INCIDENTS.REPORT_DATE. try to put this in alert and check whether it is showing as an object or null or unidentified in alert message. If it is showing as some valid object type like HTML Input Text, Input button etc otherwise it means you are passing invalid object name.

So right click the output document and view the source of web page and find the client ID of the REPORT_DATE control. Once it is done then surely document.getElementById('REPORT_DATE').value will work.

Then in your JavaScript function, try this:
function ValidateForm(form)
{
   if(document.getElementById('REPORT_DATE').value=='')  
   {
      alert('You have not entered a DATE SUBMITTED')
       document.getElementById('REPORT_DATE').focus();
       return false;
   }
 
  return true;
 
}

Author

Commented:
Here is my file...

I was reading that Acrobat is supposed to prevent submission when any field is marked "Required".  My field is marked "Required" however, the submission still occurs.


dice-test.pdf
First of all, I don't know Acrobat Editing feature as i don't have software to edit. Anyhow I have observed two points, which might be helpful to solve your problem.

1. Actually required date field (Date Submitted) is working except in first time load and user not activated the date field control. Once it is activated, it is not allowing user to submit form. To activate control, we have to click the textbox once. Then it is not allowing to leave the textbox and thrown alert message when user enters invalid date text. So you have to check why it is not working when user not activated that control. Workaround for this, set some dummy text 'dd-MMM-YYYY' text, so that alert might displayed at first time or else try to focus the control at first time, so that submit button will check this field.

2. Apart from this, I have noticed that I'm getting an error message as 'RaiseError: This operation is not permitted.
Doc.submitForm:1:XFA:DICE[0]:CEB_DICE_INCIDENTS[0]:Button5[0]:mouseDown
 ===> This operation is not permitted.'
which i can able to see this error in 'Javscript Debugger' window.

I'm using Acrobat Reader 9.3.3
Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Leakim971:

Thank you for finishing my function.  

On which event for the Submit button, would I place an alert when user clicks on Submit that will alert them that form must be filled prior to pressing submit.  Right now, nothing happens when they press Submit.

How should the alert be formatted?

Thanks again for all of your help.
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
if the button is ReadOnly there's no event to alert something when you click on it to display the message...

Author

Commented:
Is there an alert that I could when the form is opened?
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019
Commented:
This one is on us!
(Get your first solution completely free - no credit card required)
UNLOCK SOLUTION

Author

Commented:
Thanks!  Got it working.  Appreicate all of your help.
leakim971Multitechnician
CERTIFIED EXPERT
Distinguished Expert 2019

Commented:
You're welcome! Thanks for the points!
Unlock the solution to this question.
Join our community and discover your potential

Experts Exchange is the only place where you can interact directly with leading experts in the technology field. Become a member today and access the collective knowledge of thousands of technology experts.

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.