mirror of
https://github.com/ZwareBear/awx.git
synced 2026-05-14 15:58:38 -05:00
Add form-updating input validation for components
This commit is contained in:
@@ -1,5 +1,44 @@
|
||||
function link (scope, el, attrs, form) {
|
||||
form.use('input', scope, el);
|
||||
scope.config.state = scope.config.state || {};
|
||||
let state = scope.config.state;
|
||||
let input = el.find('input')[0];
|
||||
|
||||
setDefaults();
|
||||
|
||||
scope.form = form.use('input', state, input);
|
||||
|
||||
function setDefaults () {
|
||||
if (scope.tab === '1') {
|
||||
input.focus();
|
||||
}
|
||||
|
||||
state.isValid = state.isValid || false;
|
||||
state.validate = state.validate ? validate.bind(null, state.validate) : validate;
|
||||
state.check = state.check || check;
|
||||
state.message = state.message || '';
|
||||
state.required = state.required || false;
|
||||
}
|
||||
|
||||
function validate (fn) {
|
||||
let isValid = true;
|
||||
|
||||
if (state.required && !state.value) {
|
||||
isValid = false;
|
||||
} else if (fn && !fn(scope.config.input)) {
|
||||
isValid = false;
|
||||
}
|
||||
|
||||
return isValid;
|
||||
}
|
||||
|
||||
function check () {
|
||||
let isValid = state.validate();
|
||||
|
||||
if (isValid !== state.isValid) {
|
||||
state.isValid = isValid;
|
||||
form.check();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function atInputText (pathService) {
|
||||
@@ -12,7 +51,8 @@ function atInputText (pathService) {
|
||||
link,
|
||||
scope: {
|
||||
config: '=',
|
||||
col: '@'
|
||||
col: '@',
|
||||
tab: '@'
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user