Skip to content

Commit

Permalink
js: put focus on first form element
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas-Gelf committed Nov 16, 2016
1 parent 2725ef5 commit 698d523
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 11 deletions.
1 change: 1 addition & 0 deletions library/Director/Web/Form/QuickForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ protected function getActionFromRequest()

protected function setPreferredDecorators()
{
$this->setAttrib('class', 'autofocus');
$this->setDecorators(
array(
'Description',
Expand Down
36 changes: 25 additions & 11 deletions public/js/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
* Tell Icinga about our event handlers
*/
this.module.on('rendered', this.rendered);
this.module.on('beforerender', this.beforeRender);
this.module.on('click', 'fieldset > legend', this.toggleFieldset);
// Disabled
// this.module.on('click', 'div.controls ul.tabs a', this.detailTabClick);
this.module.on('click', 'input.related-action', this.extensibleSetAction);
this.module.on('focus', 'form input', this.formElementFocus);
this.module.on('focus', 'form textarea', this.formElementFocus);
this.module.on('focus', 'form select', this.formElementFocus);
this.module.on('focus', 'form input, form textarea, form select', this.formElementFocus);
this.module.icinga.logger.debug('Director module initialized');
},

Expand Down Expand Up @@ -239,12 +238,28 @@
$container.find('dd').not('.active').find('p.description').hide();
},

beforeRender: function(ev) {
var $container = $(ev.currentTarget);

var id = $container.attr('id');
var requests = this.module.icinga.loader.requests;
if (typeof requests[id] !== 'undefined' && requests[id].autorefresh) {
$container.data('director-autorefreshed', 'yes');
} else {
$container.removeData('director-autorefreshed');
}
},

containerIsAutorefreshed: function($container)
{
return $container.data('director-autorefreshed') === 'yes';
},

rendered: function(ev) {
var iid;
var $container = $(ev.currentTarget);
this.restoreContainerFieldsets($container);
this.backupAllExtensibleSetDefaultValues($container);
this.putFocusOnFirstObjectTypeElement($container);
this.highlightFormErrors($container);
this.scrollHighlightIntoView($container);
this.scrollActiveRowIntoView($container);
Expand All @@ -253,8 +268,12 @@
$('#' + iid).focus();
$container.removeData('activeExtensibleEntry');
}

// Disabled for now
// this.alignDetailLinks();
if (! this.containerIsAutorefreshed($container)) {
this.putFocusOnFirstFormElement($container);
}
},

restoreContainerFieldsets: function($container)
Expand All @@ -263,14 +282,9 @@
$container.find('form').each(self.restoreFieldsets.bind(self));
},

putFocusOnFirstObjectTypeElement: function($container)
putFocusOnFirstFormElement: function($container)
{
var $objectType = $container.find('form').find('select[name=object_type]');
if ($objectType.length) {
if ($objectType[0].value === '') {
$objectType.focus();
}
}
$container.find('form.autofocus').find('label').first().focus();
},

scrollHighlightIntoView: function ($container) {
Expand Down

0 comments on commit 698d523

Please sign in to comment.