Home
TeamSite
browser and validation-regex
System
The browser element does not seem to support validation-regex. This is pretty lame because it doesn't enforce celining-dir either (it defaults to browse there - if that directory exists - but a user can type whatever they want into the field without using the browser).
Does anyone have any information on this? It seems like setRegex should return an error for elements that don't support it.
I hate finding templating disturbances like this.
I guess I could do custom FormAPI onSave to validate, but what a freakin' pain just to work around YET ANOTHER BUG.
Find more posts tagged with
Comments
Migrateduser
Pretty confident that this is a bug that won't be fixed in any reasonable period, here is code to deal with it (which may have its own bugs). Now I don't understand why it the item remains invalid after I correct it - it's like I have to setTimeout to setValid after the redraw. What a pain.
function handleSave( button )
{
return( validateBrowserRegexes( true, true ));
}
function validateBrowserRegexes( doAlert, doRedraw )
{
var rootItems = IWDatacapture.getRootItems();
var result = true;
for ( var i = 0 ; i < rootItems.length ; i++ )
{
var test = recursiveValidateBrowserRegexes( rootItems
, result );
if ( result )
{
result = test;
}
}
if ( doRedraw && ! result )
{
IWDatacapture.setHighlightMode( true );
IWDatacapture.redrawLabels();
}
return( result );
}
function recursiveValidateBrowserRegexes( item, doAlert )
{
var result = true;
if ( item.getType() == 'browser' )
{
var check = item.getRegex();
if ( check != undefined && check != null && ! check.test( item.getValue()))
{
if ( doAlert && result )
{
alert( item.getName() + ' does not match pattern.' );
item.setValid( false );
item.setFocus();
}
result = false;
}
}
var children = item.getChildren();
if ( children != null )
{
for ( var i = 0 ; i < children.length ; i++ )
{
var test = recursiveValidateBrowserRegexes( children
, ( doAlert && result ));
if ( result )
{
result = test;
}
}
}
return( result );
}
JonathonG
Once you call setValid(false) on an item, that invalid state remains until you call setValid with either true or null. Similarly, calling setValid(true) on an item makes the item valid until setValid is called with either false or null. setValid(null) clears the valid state...the item is neither valid nor invalid.
Given the above, it is good practice to call setValid(null) at the beginning of the save sequence (onSave handler) for every item that you have code which calls setValid with either true or false. Because, when the save process starts, we should start off with no opinion about the valid state of the fields.
Jonathon
Independent Interwoven Contractor
Migrateduser
My onSave handler now first calls setValid( true ) for all browsers. TeamSite still thinks the value is not valid - at least it throws the javascript alert, but then it redraws the labels and none are red! So the sequence is:
user enter an invalid value in the field and saves
onSave handler sets item to valid
handler sets item to invalid, alerts, sets hightlight mode and redraws labels
user corrects value and saves
onsave handler sets item to valid
TeamSite alerts that data is invalid
TeamSite redraws labels with no red
onSaveDone handler fires (seems like this shouldn't happen after the alert). DCR has been written.
user presses save again and everything is fine
Seems like YET ANOTHER bug.
Migrateduser
There's an onChange on the browser that uses callServer to set another field with the selected file's size (wish that was an out-of-the-box thing). The file size field is required, but it's blanked if the file doesn't exist (when the browser element is invalid). On the next save, the callServer is not done populating the field when the Interwoven validator validates. The problem would be resolved if callServer had a synchronous option or if browser supported readonly. Whether you call that a flaw, a bug, a limitation, a feature or some combo of these types of botches it's pretty lame.
JonathonG
Three quick things I see:
1) You should be calling setValid(null) at the beginning, not setValid(true).
2) You should call setValid(false) whenever your javascript code determines something to be invalid (that will get your red labels)
3) You should return false from your save handler if there is an error. That will prevent the save from finishing.
Jonathon
Independent Interwoven Contractor