Add component controller inheritance and new inputs

This commit is contained in:
gconsidine
2017-05-18 16:57:40 -04:00
parent 1644f78cf3
commit effd537a9c
19 changed files with 295 additions and 139 deletions

View File

@@ -6,54 +6,21 @@ function atInputTextLink (scope, el, attrs, controllers) {
el.find('input')[0].focus();
}
inputController.init(formController, scope);
inputController.init(scope, formController);
}
function AtInputTextController () {
function AtInputTextController (baseInputController) {
let vm = this || {};
let scope;
let state;
let form;
vm.init = (_form_, _scope_) => {
form = _form_;
scope = _scope_;
state = scope.state || {};
state.required = state.required || false;
state.isValid = state.isValid || false;
state.disabled = state.disabled || false;
form.use('input', scope);
vm.init = (scope, form) => {
baseInputController.call(vm, 'input', scope, form);
vm.check();
};
vm.validate = () => {
let isValid = true;
if (state.required && !state.value) {
isValid = false;
}
if (state.validate && !state.validate(state.value)) {
isValid = false;
}
return isValid;
};
vm.check = () => {
let isValid = vm.validate();
if (isValid !== state.isValid) {
state.isValid = isValid;
form.check();
}
};
}
AtInputTextController.$inject = ['BaseInputController'];
function atInputText (pathService) {
return {
restrict: 'E',