Attempting to develop an Angular.js app that generates dynamic form inputs from a JSON object.
To begin with, there is a JSON object (referred to as fields):
[
{"field_id":209,"form_id":1,"name":"firstname","label":"First Name","type":"text"},
{"field_id":210,"form_id":1,"name":"lastname","label":"Last Name","type":"text"},
{"field_id":211,"form_id":1,"name":"email","label":"Email","type":"text"},
{"field_id":212,"form_id":1,"name":"picture","label":"Picture","type":"file"},
{"field_id":213,"form_id":1,"name":"address","label":"Address","type":"file"},
{"field_id":214,"form_id":1,"name":"password","label":"Password","type":"password"},
{"field_id":215,"form_id":1,"name":"","label":"","type":"submit"}
]
The key type
in the object represents the input type for a form. Displayed below:
<p ng-repeat="field in fields">
{{field.name}} : <input type="{{field.type}}" value="{{record.data[field.name]}}" />
</p>
This method works well for submit
, text
, password
, checkbox
, and radio
fields. However, when the type is file
, it defaults the input type to text
.
When I substitute {{field.name}}
with {{field.type}}
for text, it demonstrates "file" correctly.
If I manually modify
<input type="{{field.type}}"...
to <input type="file"...
, it will show a file input accurately.
Why am I unable to dynamically assign an input type as a file?