Home
TeamSite
JavaScript Validation
System
I have a APIForm that has two linked drop down list boxes that works. But I would also like to insert Javascript into this file (or other file) where I can validate form entries acrosss multiple fields. So far, I havent been able to get a customized JS alert box to appear. Is this possible via Teamsite ?.
Code sample:
function init()
// Validate some entries on the form
var filetype = IWDatacapture.getItem("/File Type");
var filesize = IWDatacapture.getItem("/File Size");
if ((filetype.getValue() == "ppt") && (filesize.getValue() == ""))
{
alert("A file size must be specified for PPT files");
return false;
}
}
Find more posts tagged with
Comments
MattP
seems like this should work. Which part is failing? The only thing I can think of, is often a string compare uses "eq" rather than "=="
Matt
Matthew Petitjean
BOC Group
Murray Hill, NJ 07974 USA
Migrateduser
What I'd like to do is to be able to do a quick validation of the form before processing the other function calls. Hence, if an error is detected by JS, I'd like to see a JS alert and halt the script from further execution - to have users correct the errors before proceeding.
The top init() call is shown here (this is within a separate JS file).
function init()
{
// Validate some entries on the form
var filetype = IWDatacapture.getItem("/File Type");
var filesize = IWDatacapture.getItem("/File Size");
if ((filetype.getValue() == "ppt") && (filesize.getValue() == ""))
{
alert("A file size must be specified for PPT files");
return false;
}
IWEventRegistry.addFormHandler("onSaveValid", onSave);
IWEventRegistry.addItemHandler("/Type", "onItemChange", onTypeSelected);
//Modified by item should be readonly.
var modifiedByItem = IWDatacapture.getItem("/Modified");
if ( modifiedByItem.getValue() == "")
{
modifiedByItem.setVisible(false);
}
modifiedByItem.setReadOnly(true);
//If this DCR is opened for reading, we need to restore the form
//to a consistent state.
if ( IWDCRInfo.getDCRName() != "" )
{
onTypeSelected( IWDatacapture.getItem("/Type") );
}
}
Jens
If /File Type and /File Size are dropdowns, you get the index with filetype.getValue(), so I think that's the reason why it doesn't.
And if there is nothing selected you got NULL.
Maybe this works:
if ((filetype.getOptions()[filetype.getValue()].text == "PPT") && (!filesize.getValue()))
{
alert("A file size must be specified for PPT files");
return false;
}
Ciao,
Jens