Commit 39311e2e authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Pieforms support for multiple js file uploads from the same form

parent 07ac8f9d
......@@ -691,6 +691,8 @@ class Pieform {/*{{{*/
'jsErrorCallback' => $this->data['jserrorcallback'],
'globalJsErrorCallback' => $this->data['globaljserrorcallback'],
'postSubmitCallback' => $this->data['postsubmitcallback'],
'newIframeOnSubmit' => $this->data['newiframeonsubmit'],
'reloadFormOnReply' => $this->data['reloadformonreply'],
));
$result .= "<script type=\"text/javascript\">new Pieform($data);</script>\n";
}
......@@ -1338,6 +1340,15 @@ EOF;
// supported in less browsers. Most modern browsers should be fine)
'jsform' => false,
// Whether the form will target a new hidden iframe every time it's
// submitted.
'newiframeonsubmit' => false,
// Whether the contents of the form should be reloaded on the page when
// a reply is received from the server. If false, error messages will
// not automatically be displayed inside the form.
'reloadformonreply' => true,
// The URL where pieforms.js and other related pieforms javascript
// files can be accessed. Best specified as an absolute path in
// pieform_configure()
......
......@@ -149,8 +149,9 @@ function Pieform(data) {//{{{
}
// Ensure the iframe exists and make sure the form targets it
self.setupIframe();
$(self.data.name).target = self.data.name + '_iframe';
// self.data.newIframes = true;
var iframeName = self.setupIframe();
$(self.data.name).target = iframeName;
appendChildNodes(self.data.name,
INPUT({
......@@ -169,26 +170,28 @@ function Pieform(data) {//{{{
PieformManager.signal('onreply', self.data.name);
var tmp = DIV();
tmp.innerHTML = data.replaceHTML;
if (self.data.reloadFormOnReply) {
var tmp = DIV();
tmp.innerHTML = data.replaceHTML;
// Work out whether the new form tag has the error class on it, for
// updating the form in the document
if (hasElementClass(tmp.childNodes[0], 'error')) {
addElementClass(self.data.name, 'error');
}
else {
removeElementClass(self.data.name, 'error');
// Work out whether the new form tag has the error class on it, for
// updating the form in the document
if (hasElementClass(tmp.childNodes[0], 'error')) {
addElementClass(self.data.name, 'error');
}
else {
removeElementClass(self.data.name, 'error');
}
// The first child node is the form tag. We replace the children of
// the current form tag with the new children. This prevents
// javascript references being lost
replaceChildNodes($(self.data.name), tmp.childNodes[0].childNodes);
self.connectSubmitButtons();
PieformManager.signal('onload', self.data.name);
}
// The first child node is the form tag. We replace the children of
// the current form tag with the new children. This prevents
// javascript references being lost
replaceChildNodes($(self.data.name), tmp.childNodes[0].childNodes);
self.connectSubmitButtons();
PieformManager.signal('onload', self.data.name);
if (data.returnCode == 0) {
// Call the defined success callback, if there is one
if (typeof(self.data.jsSuccessCallback) == 'string'
......@@ -229,6 +232,13 @@ function Pieform(data) {//{{{
this.setupIframe = function() {//{{{
var iframeName = self.data.name + '_iframe';
if (self.data.newIframeOnSubmit) {
if (!self.data.nextIframe) {
self.data.nextIframe = 0;
}
iframeName += '_' + self.data.nextIframe;
self.data.nextIframe++;
}
if ($(iframeName)) {
self.iframe = $(iframeName);
}
......@@ -240,6 +250,7 @@ function Pieform(data) {//{{{
});
insertSiblingNodesAfter(self.data.name, self.iframe);
}
return iframeName;
}//}}}
this.connectSubmitButtons = function() {//{{{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment