I have a form with a couple of fields on it and a Display Results button, which is accessible via the web.
When the button is pressed I run the following:
@Command([ToolsRunMacro]; “QueryData”)
I would like to ensure that all of the fields have a value, but am not sure if this can be done in formula language.
I tried to write all JavaScript - the validation worked fine, but when I called the agent, I couldn’t access any of the field values.
Now, I have the validation in the JSHeader. Can I use formula language to call this JavaScript validation? Or can I use formula language to do it all?
Any information would be greatly appreciated. Thanks in advance.
Subject: Form Field Validation - Is JavaScript a Must?
Lisa:
JavaScript is your best solution. What you want to do is put and graphic on the page the user is going to click on to submit the form. Make the graphic an Action hotspot. Choose JavaScript in the drop down. Call the validation() function located in your JSHeader. If the validation evaluates to be true then process the form using the document.forms[0].submit() method. If it does not evaluate then display an alert box with a listing of the fields to fill in. Once the form is sumitted using JavaScript it will run the “QueryData” agent.
Let me know if you need more information.
Chris
Subject: RE: Form Field Validation - Is JavaScript a Must?
I disagree on the use of a graphic. A Link or submit button should be used for accessibility reasons.
Subject: Form Field Validation - Is JavaScript a Must?
No, JavaScript is not a must. JavaScript is always the last thing I turn to. It’s much easier to use field validation or LotusScript.
What’s wrong with @IsValid?
Button code:
@If (@IsValid ; @Command([RunAgent]; “QueryData”) ; @SetField(“NextToDo” ; “FailedValidation” ) )
onLoad code of form:
var NextToDo = window.document.forms[0].NextToDo.value
if(NextToDo != “” ) {
window.document.forms[0].NextToDo.value = ""
switch (NextToDo) {
case "FailedValidation":
alert(“Validation Failed”)
break
}
}
The onLoad always runs after a formula button is clicked.
Another way is to use the NotesDocument method ComputeWithForm within a LotusScript agent. Either way, just set a computed-for-display field in the form (in this example, NextToDo) with a value stating what to do next and then check it in the onLoad event.
If you want to do things like give specific messages or give a field focus then you’ll need more specific formula code (or LotusScript) and you’ll need to extend the switch statement like so:
switch (NextToDo) {
case "BadAddress":
alert(“Enter a valid address”)
window.document.forms[0].Address.focus()
break
case "BadPhoneNumber":
alert(“Enter a valid phone number”)
window.document.forms[0].PhoneNumber.focus()
break
}