Kahsn
Kahsn

Reputation: 1045

Select tag not returning input data in correct form (Angular)

Using my json file, I'm making select type of questions on my web app. The code I have for my select tag is like following:

<div class="form-group" ng-class="{ 'has-error': form.$submitted && form[field.id].$invalid }" ng-if="field.type === 'select'">
   <label for="{{field.id}}">{{field.title}}</label>
   <br>
   <select ng-model="formData[field.id]" ng-value="{{value.title.id}}" ng-options="value as value.title for value in field.values">
   <option disabled selected value> -- select an option -- </option></select>
   <p class="form-group-note" ng-if="field.info" ng-bind="field.info"></p>
   <div ng-show="form.$submitted" ng-cloack>
      <span class="help-block" ng-show="form['{{field.id}}'].$error.required" ng-if="field.validations.required">Please enter a value, this field is required</span>
   </div>
</div>

I have a json file like following:

{
  "groups": [
   {
     "id": "10_8_group",
     "title": "Existence",
     "index": 60,
     "part": 10,
     "sections": [
       {
         "id": "10_8_section",
         "title": "Existence",
         "fields": [
            {
               "id": "10_8_labor_organization",
               "title": "8. Does it exist?",
               "info": "Always select \"No\"",
               "type": "select",
               "size": {
                   "width": 100,
                   "height": 1
               },
               "values": [
                   {
                       "id": 1,
                       "title": "Yes"
                   },
                   {
                       "id": 2,
                       "title": "No. If no, proceed to Part 9. and type or print your explanation."
                   }
               ]
            }
         ]
       }
     ]
   }
  ]
}

when the data is being saved in localStorage(Angular's frontend model), it saves the data as "10_8_labor_organization":{"id":1,"title":"Yes"}}

However, I would like to save this as

"10_8_labor_organization":"Yes"

How can I accomplish this??

Upvotes: 0

Views: 49

Answers (1)

Lokesh Boran
Lokesh Boran

Reputation: 99

write your code like value.id as value.title for value in field.values

Upvotes: 1

Related Questions