I created two forms. The first is so that I can submit a number of typed items to an array for display in a text box in the second form. The text box in the second form should display the items in the array as new items are added from the first form. I want to be able to delete the items in the text box and have it delete the items from the array before save. I also want to select a single item from the array as a primary name. I have an input box in the second form set up for primary name selection.
The code below has a couple of problems: 1) The text box does not add new items as they are either typed or submitted from the first form. 2) If I put information in my datastore it will show up in my text box since I set it up as an editable form but when I delete the information from the text box it does not delete it from my array (at least from what I can tell). 3) Selecting a primary name works somewhat but it is buggy and seems to only work smoothly every second time I try to change the value therein.
I was under the impression that ng-bind (or maybe ng-list?) would coordinate the data in the DOM with changes in the model. Where am I going wrong? I looked at several links on this matter that were somewhat helpful but I'm unable to fully apply them to the task at hand:
https://docs.angularjs.org/api/ng/directive/ngBind
https://docs.angularjs.org/api/ng/directive/ngList
http://codepen.io/NicholasMurray/pen/ogmLyy
http://stackoverflow.com/questions/16125872/why-ng-bind-is-better-than-in-angular
My HTML:
<form class="first-signup-inner-form" ng-submit="submit()">
<input list="names" ng-model="aliases" type="text" placeholder="Names">
<input type="submit" value="Submit">
</form>
<form class="first-signup-inner-form" editable-form name="editableForm">
<textarea class="w-input alias-text-field" id="Aliases" placeholder="All Names" name="Aliases" ng-bind="list"></textarea>
<input class="w-input business-name-text-field" list="aliases" ng-model="user.Name" id="Business-Name" type="text" placeholder="Official Name" name="Business-Name" required="required">
<datalist id="aliases"><option data-ng-repeat="alias in list" value="{{alias}}"></datalist>
</form>
JS:
$scope.list = [];
$scope.aliases = "";
$scope.submit = function(){
if ($scope.aliases){
$scope.list.push(this.aliases);
$scope.aliases = "";
}
};