Hello all. A quick rehash of the problem before I list my solution...
If you have your files in a branch subfolder like /htdocs, you will run into a problem with using file browsers in your forms. When a user selects the file in the browser, the path to the file will include the subfolder /htdocs. This is probably not want you want if your virtualization and production environments are not setup in an htdocs folder.
The solutions I've seen all seem fairly specific to a particular presentation template (in the case of perl-based solutions) or to a particular form (FormAPI solutions). I wanted to do something that would be easy and repeatable for a beginner-level forms developer to implement in any form. I also did not like the solutions that changed the value right away. I thought that might be a little confusing for the very non-technical users of the form. This fix waits until the form is submitted before fixing all the paths at once.
My way has some disadvantages, but hopefully you can adapt or improve it. Namely, I'm pretty new to forms development myself so chances are good that there is a better way. :-) If you already have some FormsAPI code, you'll have to merge this stuff into yours.
To install, create an include directory in your templatedata directory. Put the code attached to this post there.
For the forms developer, all you have to do is include the
script tag in your datacapture.cfg. This should be the last element inside your
ruleset element.
< script language="javascript" location="template-type" src="../../include/remove_htdocs.js"/ >
It works by attaching to the event that happens just after the form has passed validation and before the dcr is saved. It looks at every element of the form and if the element is a browser, it removes the htdocs from the front of the path. It works on replicants too.
BTW, I noticed something a little odd. I could not get the FormAPI to do anything until I added a dummy dtd to the data-capture-requirements element of my datacapture.cfg. My data-capture-requirements element looks like this:
< data-capture-requirements dtd-system-identifier="http://localhost/iw/dummy.dtd" dcr-validation="none" name="Name of Form" >
I look forward to your comments,
John
remove_htdocs.js:
function init() {
IWEventRegistry.addFormHandler("onSaveValid", processRoot);
}
function processRoot() {
var bigCheese = new Array();
bigCheese = IWDatacapture.getRootItems();
for (var i=0; i< bigCheese.length; i++) {
removeHtdocs(bigCheese);
}
return true;
}
function removeHtdocs(itemList) {
for (var i=0; i < itemList.length; i++) {
var possibleChildList = itemList.getChildren();
// possibleChildList is now either an itemList or null
var isParentToo = possibleChildList.length;
if (isParentToo != 0) {
removeHtdocs(possibleChildList);
}
else if (itemList.getType() == "browser") {
// i'm old school when it comes to javascript. I bet this is redundant.
if (itemList.getValue().indexOf("/htdocs") == 0) {
var newValue = itemList.getValue();
newValue = newValue.replace(/\/htdocs/, "");
itemList.setValue(newValue);
}
}
}
}
IWEventRegistry.addFormHandler("onFormInit", init);