I've got a form, which get data from API (input values,select values, which user complete earlier). I try to do "edit" function for this form. User can change form and send it back. The problem is that I need to send only ID's from input fields, but angular sends 'id + name' data. Second problem is that I need to change "status id' when user clicks on submit button.
I've tried to change ng-model, but it didn't help.
API DATA
{
status: { id: '123', name: 'new'},
name: 'some_cool_name',
section: { id: '741', name: 'sectionName';
presentaion: { id: '365', name: 'some_words'}
}
SERVICE
Object.assign(this, { getAllAwards() {
return http.get('myAPI')}.then({ data }) => return data;
}}
CONTROLLER
$scope.allAwards = awards_service.getAllAwards().then((result) => {
$scope.awards = result;
});
VIEW
<form ng-repeat="awardDraft in awards">
<input type="text" name="name" ng-model="awardDraft.name">
<select name="section" ng-model="awardDraft.section.id"
ng-options="object.id as object.name for object in sections">
</select>
<input type="text" name="presentation" ng-model="awardDraft.presentation">
</form>
EXPECTED DATA FROM FORM
{
status: 'someID',
name: 'someName',
section: 'sectionID',
presentaion: 'presentName',
}
WHAT I GET FROM MY FORM
{
status: { id: 'XXX', name: 'someStatus' },
name: 'someName',
section: { id: 'YYY', name: 'sectionName' }
presentaion: { id: 'ZZZ', name: 'presentName'}
}
I don't understand how in this case ng-model works, because if I send data from usual form, without API loading it works fine. How can I define what to send from specific input and ng-model?