Expand my Community achievements bar.

MAking text fields required using JavaScript

Avatar

Former Community Member
I have several radio button groups where, if one of the buttoms is selected, a text box becomes visible. I would like to kame these text boxes required. I am brand new at this and it took me several days to figure out that in order to make the presence = "visible" work I had to save the form as an xdp file. I am way behind on this project. Can anyone tell me how to make these text boxes required?



Thanks!



Nelson
28 Replies

Avatar

Former Community Member
You can assign the following values to the mandatory property in either FormCalc or JavaScript (no difference):







  • "disabled" -- makes the field "optional".


  • "warning" -- warns the user that the field should be filled but doesn't cause an error (i.e. form can still be submitted).


  • "error" -- makes the field required.




As for performance when it comes to changing the presence of fields on a form with over 400 objects, it wouldn't surprise me if this was
expected (I'm certainly not saying it's
acceptable, just that it may be
expected) performance.



Stefan

Adobe Systems

Avatar

Former Community Member
Thanks!



Any idea why making fields visible takes so much longer than making them mandatory?



Nelson

Avatar

Former Community Member
> Any idea why making fields visible takes so much longer than making

> them mandatory?



Yes, as I mentioned when you set a field to visible Acrobat has to recompute the layout of the PDF to account for the new field. That takes time. Setting something to mandatory just involves setting a property on the field and then there's no more work.



Chris

Adobe Enteprise Developer Support

Avatar

Former Community Member
Hi,



I've been trying to customize the error message and I've tried using examples from this post. I always get a generic message saying some field hasn't been filled in, but never the message I've tried to implement.



Here's my code:



TextField1.mandatory = "error"

TextField1.mandatoryMessage = "mandatory field!"



pls hlp



W

Avatar

Former Community Member
Hi Wil,



Are you specifying JavaScript or FormCalc as the scripting language for your code?



What you specified above should work in FormCalc but if you've specified JavaScript, it would generate an error because you're missing semicolons at the end of every line:



TextField1.mandatory = "error";

TextField1.mandatoryMessage = "mandatory field!";


Try pressing [Ctrl + J] while the form is loaded in Acrobat (works in the Preview pane in LC Designer as well) to see if there's an error message of some sort.



Also note that your custom "mandatory message" will only be displayed in the event that TextField1 has a value and this value is then removed completely (e.g. specify a value in TextField1, exit the field by tabbing-out or clicking somewhere else, enter the field again, remove the value and tab/click-out again). It won't be used when attempting to submit the form with an empty TextField1 field (in this case, Acrobat will show a generic error message indicating that "at least one mandatory field" wasn't filled).



Stefan

Adobe Systems

Avatar

Level 1
Hi there



I am just starting to develop Adobe forms and this is the exact situation I am trying to resolve in my own form.

I don't have any real experience with JavaScript but can understand the logic and was wondering if someone can provide me with the script needed to turn on/off the mandatory setting for a number of fields

based on selection of a radio button?

Any advice or help much appreciated.



Thanks

John Crossley

Avatar

Level 4
To affect serveral fields you will need to use one of two strategies. First you could reference the fields explicitly using code similar to what is posted above. Or you could use the "resolveNodes" function to acquire groups of files. Since you are unfamiliar with JavaScript I would suggest the first strategy.



Thom Parker

WindJack Solutions

The source for PDF Scripting Info


pdfscripting.com




The Acrobat JavaScript Reference, Use it Early and Often

http://www.adobe.com/devnet/acrobat/javascript.html

Avatar

Level 1
Thanks Thom



I believe that I am using the correct piece of code and am trying to test it on a single field before I define all fields explicitly.



I have set the following on the click event of a checkbox but there does not seem to be any change to the field I am trying to make visible and mandatory.



topmostSubform.Page1.TravelAllowance::click - (JavaScript, client)



if ($.rawValue == "On") then

if (txtAccountName.mandatory == "disabled") then

txtAccountName.mandatory == "error"

endif

if (txtAccountName.presence == "invisible") then

txtAccountName.presence == "visible"

endif



else

if (txtAccountName.presence == "visible") then

txtAccountName.presence == "invisible"

endif

if (txtAccountName.mandatory == "error") then

txtAccountName.mandatory == "disabled"

endif

endif



Do you have any suggestions.



thanks