System: TS 6.5 SP2 on Win2K
I'm populating a text item in my DCT using a CGI callout (it's a visual colour picker using
Farbtastic which populates the text box with an HTML hex triplet colour value). The actual colour picker works great and the picked colour's hex value gets placed in the text box OK.
Trouble is, it's a complex DCT and after adding quite a few big replicants, using the "opener.top.datacapture.refreshForm()" method from the callout's javascript was taking an age to update the entire DCT. Well, not exactly an age but long enough to be very annoying for users. To be fair, the FormsPublisher Dev Guide does say that refreshForm() is very expensive and should be used sparingly...
So I'm trying to use the refreshItem(formElement) method instead, as recommended on page 92/93 of the above dev guide.
The trouble is, I'm not getting any JavaScript errors and the code seems to match the syntax in the guide, but it's not working.
The callout correctly puts the colour string (e.g. #ffffff) in the text box, but FormsPublisher doesn't save the value when the DCR is saved. If the user populates the box using the callout but then clicks into the text field and away from it again, the value is correctly saved in the DCR. It seems like it's my refreshItem call which is failing.
Here is the relevant JavaScript from my CGI:
// function to set the callout item's value to whatever we have chosen with the colour picker
function set_datacapture_item_value( selectedValue ) {
if ((window.opener == null) || (window.opener.closed)) {
alert("Can't find DCT window. Was it closed?");
return false;
}
var calloutForm = eval($form_name);
if (!calloutForm) {
alert("Can't find callout form. Does it exist?");
return false;
}
// hunt for our callout element in the DCT form (this is safer than directly setting the value in case the field doesn't exist)
var calloutElementFound = false;
for ( i = 0 ; i < calloutForm.elements.length ; i++ ) {
if (calloutForm.elements.name == '$element_name') { // the element name has been placed here by Perl!
calloutForm.elements.value = selectedValue;
calloutElementFound = true;
break;
}
}
if (!calloutElementFound) {
return false;
}
return true;
}
// function to handle the process of closing the callout window after updating the callout item on the DCT
function handle_selection() {
// check that we've been able to update the correct item on the DCT first
if (callback()) {
if(opener.top.datacapture) {
// following line is the default method for callback updates, but is too slow for big templates like SH
//opener.top.datacapture.refreshForm();
opener.top.datacapture.refreshItem('$element_name');
}
self.close();
}
else {
alert('Please choose a colour.');
}
}
// function to do callback to DCT (via set_datacapture_item_value function)
function callback() {
// chosencolour is the value of the textbox (called colour) on this callout popup form
var chosencolour = document.callout_form.colour.value;
if (!set_datacapture_item_value( chosencolour )) {
alert('Could not update template item. Did you close the datacapture window?');
}
return true;
}
Note that the $element_name bits are populated with the actual callout item name by the Perl in the CGI, using $cgi->{'form'}{'iw_callback_var'}; to give e.g. seasonalhomepage/c_background/bgcolour.
Any advice would be greatly appreciated. Thanks!