-1

I have the HTML like below

<div class="col-md-12">
  <div class="col-md-4" ng-class="{ 'has-error' : submitted && form.field_format.$invalid }">
    <label for="field_format">Type</label>
    <select class="form-control" name="field_format" id="field_format" data-ng-model="form.field_format" required>
      <option value="text">Text</option>
      <option value="image">Image</option>
    </select>
    <div ng-show="submitted && form.field_format.$invalid" class="help-block">
      <p ng-show="form.field_format.$error.required">Field format is required</p>
    </div>
  </div>

  <div class="col-md-7" ng-class="{ 'has-error' : submitted && form.field_value.$invalid }">
    <label for="field_value">Value</label>
    <input type="text" class="form-control" name="field_value" id="field_value" data-ng-model="form.field_value" placeholder="Enter Value" required/>
    <div ng-show="submitted && form.field_value.$invalid" class="help-block">
      <p ng-show="form.field_value.$error.required">Field value is required</p>
    </div>
  </div>
</div>

I want to implement the following functionalities

  1. On Change the field_format from the select box, change the field_value input type to text/file
  2. Upload file/text

I have read How to upload file using angular and the NodeJS uploading file is working for me, but I am not sure how can I achive the uploading file / text in the dynamic form like this?

The select box is rendering with the <option value="? undefined:undefined ?"></option> How can I make it to select the text default?

Kara
  • 6,115
  • 16
  • 50
  • 57
Dau
  • 8,578
  • 4
  • 23
  • 48

1 Answers1

1

Create a hidden input (with ng-hidden, e.g.) for your file, and when the change event is fired, change a property in your controller so that the input becomes visible.

Stuart Nelson
  • 4,202
  • 2
  • 23
  • 26
  • Thanks by using this the input types is changing but the problem is I have the require validation on the field and file type input doesn't bind witht the ng-model, so how can I manage the validation with it too? – Dau Aug 26 '15 at 11:23