mgCrud como modulo npm externo, vnFocus sobre botones
This commit is contained in:
parent
f4a5274a9a
commit
efac73f4bc
|
@ -1,3 +1,9 @@
|
|||
|
||||
<!--
|
||||
<mg-ajax path="/client/api/Clients" options="mgIndex as index"></mg-ajax>
|
||||
<button ng-click="index.accept()"></button>
|
||||
<span ng-repeat="client in index.model">{{client}}</span>
|
||||
-->
|
||||
<div margin-medium>
|
||||
<div style="max-width: 40em; margin: 0 auto;">
|
||||
<vn-card>
|
||||
|
|
|
@ -1,16 +1,25 @@
|
|||
import {module} from '../module';
|
||||
|
||||
// Sets the focus and selects the text on the input.
|
||||
|
||||
/**
|
||||
* Sets the focus and selects the text on the input.
|
||||
*/
|
||||
export function directive() {
|
||||
return {
|
||||
restrict: 'A',
|
||||
link: function($scope, $element, $attrs) {
|
||||
$scope.$watch($attrs.vnFocus, function(value) {
|
||||
if ($element[0].getElementsByTagName("INPUT")[0])
|
||||
$element[0].getElementsByTagName("INPUT")[0].focus();
|
||||
if ($element[0].getElementsByTagName("TEXTAREA")[0])
|
||||
$element[0].getElementsByTagName("TEXTAREA")[0].focus();
|
||||
$scope.$watch('', function() {
|
||||
let input = $element[0];
|
||||
let selector = 'input, textarea, button, submit';
|
||||
|
||||
if(!input.matches(selector))
|
||||
input = input.querySelector(selector);
|
||||
if(!input)
|
||||
throw new Error(`vnFocus: Can't find a focusable element`);
|
||||
|
||||
input.focus();
|
||||
|
||||
if(input.select)
|
||||
input.select();
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
@ -8,8 +8,17 @@ import {kebabToCamel} from '../lib/string';
|
|||
export function directive() {
|
||||
return {
|
||||
restrict: 'A',
|
||||
require: [],
|
||||
link: function($scope, $element, $attrs) {
|
||||
$scope[kebabToCamel($attrs.vnId)] = $element[0].$ctrl;
|
||||
let id = kebabToCamel($attrs.vnId);
|
||||
let controller = $element[0].$ctrl;
|
||||
|
||||
if(!id)
|
||||
throw new Error(`vnId: Attribute can't be null`);
|
||||
if(!controller)
|
||||
throw new Error(`vnId: Can't find controller for element '${id}'`);
|
||||
|
||||
$scope[id] = controller;
|
||||
}
|
||||
};
|
||||
};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
export * from './angular';
|
||||
export * from './oc-lazy-load';
|
||||
export * from './ui-router';
|
||||
export * from './mg-crud';
|
||||
export * from './oc-lazy-load';
|
||||
export * from './angular-translate';
|
||||
export * from './material-design-lite';
|
||||
export * from './angular-paging';
|
||||
export * from './validator';
|
||||
//export * from './mg-crud';
|
|
@ -15,7 +15,7 @@
|
|||
"angular-translate-loader-partial": "^2.13.1",
|
||||
"angular-ui-router": "^1.0.0-beta.3",
|
||||
"material-design-lite": "^1.3.0",
|
||||
"mg-crud": "^1.0.1",
|
||||
"mg-crud": "^1.1.2",
|
||||
"oclazyload": "^0.6.3",
|
||||
"validator": "^6.2.1"
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue