Commit 2e7a0c11 authored by Richard Mansfield's avatar Richard Mansfield
Browse files

Added element for js form messages to table renderer in forms package

parent 82285eba
......@@ -60,10 +60,13 @@ function submitForm(formid,url,callback) {
var d = sendXMLHttpRequest(req,queryString(data));
d.addCallback(function (result) {
var data = evalJSONRequest(result);
displayMessage({'message':data.message,'type':data.success});
var type = data.success ? 'infomsg' : 'errmsg';
eval(formid + '_message(\'' + data.message + '\',\'' + type + '\')');
callback();
});
d.addErrback(function() { displayMessage(get_string('unknownerror'),'error'); });
displayMessage({'message':get_string('processingform'),'type':'info'});
d.addErrback(function() {
eval(formid + '_message(\'' + get_string('unknownerror') + '\',\'' + 'errmsg\')');
});
eval(formid + '_message(\'' + get_string('processingform') + '\',\'' + 'infomsg\')');
return false;
}
......@@ -403,6 +403,10 @@ class Form {
foreach ($this->elements as $name => $elem) {
$result .= form_render_element($elem, $this);
}
$function = 'form_renderer_' . $this->renderer . '_messages';
if (function_exists($function)) {
$result .= $function($this->name);
}
$function = 'form_renderer_' . $this->renderer . '_footer';
if (function_exists($function)) {
$result .= $function();
......@@ -579,11 +583,11 @@ class Form {
$js_error_function = 'form_renderer_' . $this->renderer . '_error_js';
if (!function_exists($js_error_function)) {
@include_once('form/renderers/' . $this->renderer . '.php');
if (!function_exists($js_error_function)) {
throw new FormException('No such renderer function "' . $js_error_function . '"');
}
}
return $result . $js_error_function($this->name);
if (function_exists($js_error_function)) {
return $result . $js_error_function($this->name);
}
return $result;
}
/**
......
......@@ -101,6 +101,11 @@ function form_renderer_table_footer() {
return "</table>\n";
}
function form_renderer_table_messages($formid) {
// Element to hold messages relating to the whole form (used in javascript submission).
return "\t<tr id=\"" . $formid . "_msg\"><td colspan=\"2\" class=\"errmsg\"></td></tr>\n";
}
function form_renderer_table_error_js($id) {
$result = 'function ' . $id . '_set_error(id,m) {';
$result .= "swapDOM($(id),TR({'id':id},TD({'colspan':2,'class':'errmsg'},m)));";
......@@ -108,6 +113,9 @@ function form_renderer_table_error_js($id) {
$result .= 'function ' . $id . '_rem_error(id) {';
$result .= "swapDOM($(id),TR({'id':id,'style':'display:none;'},TD(null)));";
$result .= "}\n";
$result .= 'function ' . $id . '_message(m,type) {';
$result .= "replaceChildNodes($('" . $id . "_msg'),TD({'colspan':2,'class':type},m));";
$result .= "}\n";
return $result;
}
......
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