[Solved] Create form programatically

Hello,

I’m migrating my app from Dojo to Ionic and I’m having troubles with a “Survey” part of the app. Source data for a form with questions and answer controls (radio / checkbox / textarea) is loaded dynamically from remote database.

In Dojo I created widgets, but in Ionic I didn’t find a way how to make it work; the only way I figured was to generate a string with the HTML form and use ng-bind-html, which doesn’t work (text of questions appears, but no form controls - no inputs or textareas are present, when I inspect the final HTML code using dev tools in the browser). So I assume this is a wrong approach… :blush:

Please, what is the right one?
Thank you.

Have you had any experience with angularjs? If yes, you could do the following:

in controller:

$scope.formControls = [
   {id: 'forminput1', type: 'text', value: '', placeholder: 'Enter your username here..'},
   {id: 'forminput2', type: 'date, value: '01-01-1970', placeholder: 'Enter your date here..'}
];

In view:

<div ng-repeat="formControl in formControls">
   <div ng-if="formControl.type == 'text' ">
      <input type="{{formControl.type}}" id="{{formControl.id}}" value="{{formControl.value}}" placeholder="{{formControl.placeholder}}">
   </div>
</div>

It could be something like this, haven’t tried any of the above code, but it should give you an idea for an approach :slight_smile:

1 Like

That’s exactly what I needed, thank you! I appreciate the fast reply as well.

Glad to hear! Let us know if you managed to do it :slight_smile: