Added focus directive
The focus directive allows us to autofocus a particular element (assuming it supports keyboard focus) when it is rendered to the DOM. The example use case is the search page, where the input text field is automatically selected. Change-Id: Ib2ec35134be5c667ea01b48433815a857d00c6d2
This commit is contained in:
parent
6f72378cca
commit
003c41fdc6
@ -23,6 +23,7 @@
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group has-feedback has-feedback-no-label">
|
||||
<div id="search-criteria"
|
||||
focus
|
||||
tag-complete="criteria as criteria.title for criteria in searchForCriteria($viewValue)"
|
||||
tag-complete-tags="criteria"
|
||||
tag-complete-label-field="title"
|
||||
|
37
src/app/util/directive/focus.js
Normal file
37
src/app/util/directive/focus.js
Normal file
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2014 Hewlett-Packard Development Company, L.P.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
* not use this file except in compliance with the License. You may obtain
|
||||
* a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* This directive may be attached to input elements, and calls the 'focus()'
|
||||
* method on that element whenever it is added to the DOM (whenever the link())
|
||||
* phase is run)
|
||||
*/
|
||||
angular.module('sb.util').directive('focus',
|
||||
function () {
|
||||
'use strict';
|
||||
|
||||
return {
|
||||
link: function ($scope, $element) {
|
||||
|
||||
// Extract the element...
|
||||
var e = $element[0];
|
||||
|
||||
if (!!e && e.hasOwnProperty('focus')) {
|
||||
e.focus();
|
||||
}
|
||||
}
|
||||
};
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user