I have a pretty complex object that I need to send from a form in Angular.
Basically the object looks like this:
vm.formData = {
active: 1,
parse_tree : {
exlude: [],
include: [],
tag: ''
},
tag: '',
term: ''
}
My problem is creating new objects inside the include or exclude arrays.
Not sure how to do that.
Basically if you type in a tag name inside the row with "With all of these" as the label, it needs to create a new object inside of the include array, and if you click the checkbox 'Exact match' next to the tag input, it needs to add exact : 1. If 'Exact match' is unchecked, then exact : 0.
parse_tree : {
exlude: [],
include: [
{
exact: 1,
term: "hello"
}
],
tag: ''
}
My form HTML:
<div class="row">
<div class="col-sm-2 advanced-label">Main Tag:</div>
<div class="col-sm-4">
<input ng-model="tc.formData.term"
id="new-main-tag"
type="text"
class="form-control"
placeholder="tag">
<input ng-model="tc.formData.parse_tree.include.obj.exact"
ng-true-value="1" ng-false-value="0"
for="new-main-tag"
type="checkbox">
<em>Exact match</em>
</div>
<div class="col-sm-4">
<select ng-model="tc.formData.tag"
class="form-control manage-source-input-tag">
<option value="companies">companies</option>
<option value="news" selected="">news</option>
<option value="people">people</option>
<option value="products">products</option>
</select>
</div>
<div class="col-sm-2">
<button ng-click="tc.showSimpleForm()"
class="btn btn-info btn-sm switch-btn">Switch to simple</button>
</div>
</div>
<div class="row">
<div class="col-sm-2 advanced-label">
With all of these:
</div>
<div class="col-sm-2">
<input ng-model="tc.withAll1"
id="with-all-1" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-all-1">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withAll2"
id="with-all-2" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-all-2">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withAll3"
id="with-all-3" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-all-3">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withAll4"
id="with-all-4" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-all-4">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withAll5"
id="with-all-5" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-all-5">
<em>Exact match</em>
</div>
</div>
<div class="row">
<div class="col-sm-2 advanced-label">
With none of these:
</div>
<div class="col-sm-2">
<input ng-model="tc.withNone1"
id="with-none-1" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-none-1">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withNone1"
id="with-none-2" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-none-2">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withNone1"
id="with-none-3" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-none-3">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withNone1"
id="with-none-4" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-none-4">
<em>Exact match</em>
</div>
<div class="col-sm-2">
<input ng-model="tc.withNone1"
id="with-none-5" type="text" class="form-control" placeholder="tag">
<input type="checkbox" for="with-none-5">
<em>Exact match</em>
</div>
</div>
<div class="row">
<div class="col-sm-2 advanced-label">Tag Notes:</div>
<div class="col-md-5">
<textarea></textarea>
<input type="checkbox" aria-label="exact-match">
<em>Unsure</em>
</div>
<div class="col-md-5"></div>
</div>
<div class="row advanced-action-row">
<button class="btn btn-success btn-sm manage-term-add">Save</button>
</div>