Expand my Community achievements bar.

Don’t miss the AEM Skill Exchange in SF on Nov 14—hear from industry leaders, learn best practices, and enhance your AEM strategy with practical tips.

REQUIRED FIELDS

Avatar

Level 6

Hello,

I have a form which has several checkboxes.  A couple of them requires a date field to be entered in a box next to it.  If the user checks the box which has a date field box next to it, I want the form to do the following:

1.  Let the user know that they have to enter/pick a date for that box.  The JavaScript I entered is below.

2.  Stop the user from sending the form via email, printing the form and saving the form if the date is not entered in the box. 

I entered the below JavaScript in the click event of the checkbox.  I found it on the internet and it doesn't seem to work.  FYI - I changed the value of the date field boxes to "user optional" and then I changed it to "user required" and it still does not work like I want it.   Can anyone help?

 

if(this.rawValue == 1)
{
this.parent.warrant.mandatory = "error";
}
else
{
this.parent.warrant.mandatory = "disabled"}

 

Thank you.

11 Replies

Avatar

Employee

Not sure where you got this sample script from but it is not completely correct

Here is my sample form

Kosta_Prokopiu1_0-1603696839997.png

The logic is in the check box and looks like this:

if (this.rawValue == 1) {
  DateField1.validate.nullTest="error";
} else {
  DateField1.validate.nullTest="disabled";
}

The result is: the moment I check the box the associated DateField1 becomes mandatory and depending on your Reader settings a red frame shows up:

Kosta_Prokopiu1_1-1603696938768.png

and when you try to submit it will reject

Kosta_Prokopiu1_2-1603696990002.png

 

Avatar

Level 6
Hello, That's exactly what I want, but it's still not working. When I check the box it still allows me to send via email, etc. and the red box does not show up when I click the box. At first, I had the "warrant" box as "user required" which showed a red box when I opened the form. Then when I checked the box, the red box disappeared and it allowed me to send, etc. So, I changed it to "user optional" which does not show a red box when you open the form and it also does not become red when I check the box and it still allows me to send, etc. On a separate note, if I just make all date field "user required" without entering a javascript, the form won't allow me to send unless I enter a date in all of the date fields. I don't want that. I only want it to work when I check a specific box that requires a date field in that specific box.

Avatar

Level 6
Hello, That's exactly what I want, but it's still not working. When I check the box it still allows me to send via email, etc. and the red box does not show up when I click the box. At first, I had the "warrant" box as "user required" which showed a red box when I opened the form. Then when I checked the box, the red box disappeared and it allowed me to send, etc. So, I changed it to "user optional" which does not show a red box when you open the form and it also does not become red when I check the box and it still allows me to send, etc. On a separate note, if I just make all date field "user required" without entering a javascript, the form won't allow me to send unless I enter a date in all of the date fields. I don't want that. I only want it to work when I check a specific box that requires a date field in that specific box.

Avatar

Level 6
Also, I do not have an email button. Not sure if that's why it doesn't work. I don't want to add an email button either. I would like them to use the email button that is already in acrobat reader,

Avatar

Employee

Ok, several things:

 

If you use this PDF in Adobe Reader you will need to have Reader Extensions applied either by using Acrobat Pro or AEM Forms server software - otherwise it will not allow to submit the entered data.

The logic I showed you will only change the state of the field from non-mandatory to mandatory and back and must be in the change event of the check-box - I realized that I did not mention that.

The Send as Email functionality of Reader will also heed the mandatory state of the fields (if they are mandatory) - there should not be a difference to using the Email Submit button.If your logic fails to make a mandatory field mandatory then it is no surprise that it will send the E-Mail right away.

 

Here is my sample for download https://documentcloud.adobe.com/link/review?uri=urn:aaid:scds:US:2302891b-1ad4-45b7-956b-4df43bb7344...

 

 

Avatar

Level 6
I checked the sample and you have an email button on it which works but I don't want to add an email button to the form. When I click the email envelope, an empty box appears. Can you fix that? Also, should is the object value of your date field block "required" or "optional"?

Avatar

Employee
As I have mentioned in my post, the E-Mail button is not needed, you should be able to submit also from the built in e-mail functionality. What empty box? When I use the email button I get to select the e-mail client to use.

Avatar

Level 6
Ok, now I get "select the email client". I had to close and then reopen Reader. My apologies. Shouldn't I get the error message when I try to submit via the built in e-mail button?

Avatar

Level 6
I checked the sample and you have an email button on it which works but I don't want to add an email button to the form. When I click the email envelope, an empty box appears. Can you fix that? Also, should is the object value of your date field block "required" or "optional"?

Avatar

Level 6
Good morning. I posted this on 11/11/20 and have not received a response on my question. I'm not sure if I'm posting correctly. Please respond if you are able to see this.......Ok, now I get "select the email client". I had to close and then reopen Reader. My apologies. Shouldn't I get the error message when I try to submit via the built in e-mail button if the box is checked and date box is blank?

Avatar

Employee

Ok, I show you how the form works here. The Submit button is hidden, I use the E-Mail button upper right only:

Kosta_Prokopiu1_0-1606213348319.png

No Checkbox selected - means no mandatory - E-Mail can be sent:

Kosta_Prokopiu1_1-1606213423978.png

Checkbox selected - means mandatory field - no email can go out unless you fill the field:

Kosta_Prokopiu1_2-1606213469826.png

Kosta_Prokopiu1_3-1606213500553.png

Date filled, E-Mail button clicked, E-Mail can be sent.

Kosta_Prokopiu1_0-1606213767738.png

 

I cannot explain why this is NOT working for you unless you have made a mistake in your implementation. Did you try my sample not using the Submit button on the form?