Commit 7ac94d40 authored by Nigel McNie's avatar Nigel McNie
Browse files

Fix for bug #1717 - Hitting enter in a text field adds a column on the extreme left

The fix basically works by adding a hidden submit button at the very beginning of the form. Its "name" is the same as for whatever current action is being performed. Thus, when enter is pressed, the same value is passed through.

In javascript mode, this form element's name attribute is poked every time a new element is configured to be correct for that. There is also some special event handling for the search tab of the artefact chooser, so it does not trigger a form submit - just a 'click' event on the correct button.
parent 00f1c162
......@@ -285,6 +285,7 @@ function ViewManager() {
};
contentDiv.innerHTML = data.data['html'];
eval(data.data.javascript);
$('action-dummy').name = getNodeAttribute(e.src(), 'name');
// Make the cancel button be supersmart
var cancelButton = $('cancel_cb_' + blockinstanceId + '_action_configureblockinstance_id_' + blockinstanceId);
......@@ -855,6 +856,7 @@ function ViewManager() {
'oldcontent': '',
'button' : configureButton
};
$('action-dummy').name = 'action_addblocktype_column_' + whereTo['column'] + '_order_' + whereTo['order'];
setNodeAttribute(configureButton, 'disabled', 'disabled');
}
......
......@@ -180,9 +180,18 @@ if (ul) {
e.stop();
});
connect('artefactchooser-searchfield', 'onkeypress', function(e) {
if (e.key().code == 13) { // enter pressed - submitting form
e.stop();
signal('artefactchooser-searchsubmit', 'onclick', true);
}
});
// Wire up the search button
connect('artefactchooser-searchsubmit', 'onclick', function(e) {
e.stop();
if (e._event != true) {
e.stop();
}
var loc = searchA.href.indexOf('?');
var queryData = [];
......
......@@ -3,6 +3,7 @@
{include file="columnfullstart.tpl"}
<form action="{$formurl}" method="post">
<input type="submit" name="{$action_name}" id="action-dummy" class="hidden">
<input type="hidden" id="viewid" name="id" value="{$view}">
<input type="hidden" name="change" value="1">
<input type="hidden" id="category" name="c" value="{$category}">
......
......@@ -60,6 +60,24 @@ $smarty->assign('columns', $columns);
// Tell smarty we're editing rather than just rendering
$smarty->assign('editing', true);
// Work out what action is being performed. This is used to put a hidden submit
// button right at the very start of the form, so that hitting enter in any
// form fields will cause the correct action to be performed
foreach (array_keys($_POST + $_GET) as $key) {
if (substr($key, 0, 7) == 'action_') {
if (param_boolean('s')) {
// When configuring a blockinstance and the search tab is open,
// pressing enter should search
$key = str_replace('configureblockinstance', 'acsearch', $key);
if (substr($key, -2) == '_x') {
$key = substr($key, 0, -2);
}
}
$smarty->assign('action_name', $key);
break;
}
}
$smarty->assign('formurl', get_config('wwwroot') . 'view/blocks.php');
$smarty->assign('category', $category);
$smarty->assign('new', $new);
......
Supports Markdown
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