Highlighted

Subimisson with required fields

Avatar

29-12-2008

I am having a problem with submitting a form that contains required fields. The secenrio is I have two checkboxes and two subforms each subform containing one textfield. The subforms are both hidden. If the user selects checkbox one then subform one becomes visible the textfield one in subform one gets highlited red because it is a required field. If user selects checkbox two then subform two becomes visible and same secenrio with textfield two in subform two. So if user opens form and selects checkbox two then subform two becomes visible and then if user does not enter information in textfield two then you get an error, but if user enters information in textfield two then form should be submitted but it does not submit. The funny thing is checkboxes actually works and everything works ONLY if you go through all the checkboxes selecting and deselecting them form the beginnning. But if you open up the form and only select one of the checkboxes and fill out the texfied it won't submit. I know this sounds a confusing but I dont know how else to put it. I will post the code (using Formcalc) for better understanding.



Code for checkbox1



if (AccruedAnnualLeave ==0) then

form1.page1.sub1.presence = "invisible";

form1.page1.sub1.AccruedAnnLvFromDate.presence = "invisible";

endif

if (AccruedAnnualLeave ==1) then

form1.page1.sub1.presence = "visible";

form1.page1.sub1.AccruedAnnLvFromDate.presence = "visible";

endif



Code for checkbox2



if (RestoredAnnualLeave ==0) then

form1.page1.sub2.presence = "invisible";

form1.page1.sub2.RestoredAnnLvFromDate.presence = "invisible";

endif

if (RestoredAnnualLeave ==1) then

form1.page1.sub2.presence = "visible";

form1.page1.sub2.RestoredAnnLvFromDate.presence = "visible";

endif

Replies

Highlighted

Avatar

Avatar

yodadobe

Avatar

yodadobe

yodadobe

29-12-2008

If it works after selecting then deselecting, then maybe put the deselect logic in the initialize as well.
Highlighted

Avatar

29-12-2008

In the Initialize stage I put in the deselect logic for both checkboxes:



For Checkbox one



if (AccruedAnnualLeave ==0) then

form1.page1.sub1.presence = "invisible";

form1.page1.sub1.AccruedAnnLvFromDate.presence = "invisible";

endif



For checkbox two



if (RestoredAnnualLeave ==0) then

form1.page1.sub2.presence = "invisible";

form1.page1.sub2.RestoredAnnLvFromDate.presence = "invisible";

endif



But it still doesnt work the first time you open the form
Highlighted

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

05-01-2009

When you say it doesn't work .....what doesn't work?
Highlighted

Avatar

08-01-2009

What I mean is no matter how many fields using the same logic the form does not work the first time you open it. For example if a person opened the form with 5 checkboxes available and only selected the frist 2 and tried to submit the form it won't submit because its still reading the required fields although the subform and the fields associated with it are invisible. But if the user selects and deselects all the checkboxes even the ones the user does not need then logic starts to work and the user can pick which checkboxes they need to check along with associated fields and the form will submit. Bascially the logic only works if you go through all the checkboxes in the begining.
Highlighted

Avatar

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692

Avatar

pguerett

Total Posts

7.7K

Likes

611

Correct Answer

692
pguerett

08-01-2009

If a field is marked as required then Acrobat is expecting to have a value for it whether it is hidden, visible or invisible. If you do not want this behaviour you will have to adjust the mandatory property of the field along with the presence property when you make it visible/invisible.
Highlighted

Avatar

16-01-2009

Okay well that statement makes sense but I was still curious because I know it is all about the scripting and I know there is the right script out there to do this, so I still kept searching and I found it. You just have to add a validate link with the checkbox so my scripts for the two checkboxes are as follows:



if (AccruedAnnualLeave ==0) then

form1.page1.sub1.presence = "invisible";

form1.page1.sub1.AccruedAnnLvFromDate.presence = "invisible";

endif

if (AccruedAnnualLeave ==1) then

form1.page1.sub1.presence = "visible";

form1.page1.sub1.AccruedAnnLvFromDate.presence = "visible";

form1.page1.sub1.AccruedAnnLvFromDate.validate.nullTest = "error"

endif



if (RestoredAnnualLeave ==0) then

form1.page1.sub2.presence = "invisible";

form1.page1.sub2.RestoredAnnLvFromDate.presence = "invisible";

endif

if (RestoredAnnualLeave ==1) then

form1.page1.sub2.presence = "visible";

form1.page1.sub2.RestoredAnnLvFromDate.presence = "visible";

form1.page1.sub2.RestoredAnnLvFromDate.validate.nullTest = "error"

endif



With this script my form is working correctly, as you see you need to add the validate.nullTest code to get it working properly. I found this code and many others at http://www.adobe.com/devnet/livecycle/designer_scripting_samples.html#changing_appearance

I hope this will help others in the future.