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') ...@@ -31,19 +31,32 @@ angular.module('reportApp')
scope: { scope: {
}, },
link: function(scope){ link: function(scope){
scope.createGroup = GroupsService.createGroup;
scope.newGroupName = { val: '' }; 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: ` template: `
<form> <form ng-submit='createGroup()'>
<div class='form-group'> <div class='form-group' ng-class="{'has-error': hasError(newGroupName.val)}">
<div class="input-group"> <div class="input-group">
<span class="input-group-btn"> <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> <i class="fa fa-plus" aria-hidden="true"></i>
</button> </button>
</span> </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>
</div> </div>
</form> </form>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment