Skip to content
Snippets Groups Projects
Commit 315acf22 authored by Jaden Diefenbaugh's avatar Jaden Diefenbaugh
Browse files

addgroup has enter key support, input validation

parent a9020ca2
No related branches found
No related tags found
1 merge request!223Reports overhaul
......@@ -31,19 +31,32 @@ angular.module('reportApp')
scope: {
},
link: function(scope){
scope.createGroup = GroupsService.createGroup;
scope.newGroupName = { val: '' };
scope.hasError = (val) => {
// if val is undefined, empty, or a dup, its an err
const isErr = !val || val.length === 0 || GroupsService.groups.find(g => g.name === val);
// cast to boolean
return !!isErr;
};
scope.createGroup = () => {
if(scope.hasError(scope.newGroupName.val)){
return;
}
GroupsService.createGroup(scope.newGroupName.val);
scope.newGroupName.val = '';
};
},
template: `
<form>
<div class='form-group'>
<form ng-submit='createGroup()'>
<div class='form-group' ng-class="{'has-error': hasError(newGroupName.val)}">
<div class="input-group">
<span class="input-group-btn">
<button ng-click='createGroup(newGroupName.val)' class="btn btn-default" type="button">
<button ng-click='createGroup()' class="btn btn-default" type="button">
<i class="fa fa-plus" aria-hidden="true"></i>
</button>
</span>
<input id='createNewGroupInput' ng-model='newGroupName.val' type="text" class="form-control" placeholder="New group name...">
<input required id='createNewGroupInput' ng-model='newGroupName.val' type="text" class="form-control" placeholder="New group name...">
</div>
</div>
</form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment