Using Angular Formly I've setup the following controller and template. I get the controller to print the values that the user has entered into all the fields, except those that the user hasn't touched. This means that if the user doesn't write anything at all in a field, that field is not included. Though if the user enters something and then deletes it, the field is included with an empty string.
How do I include the fields that the user hasn't touched?
// fooController.js
vm.fooModel= {};
vm.fooFields = [
{
key: 'foo',
type: 'input'
templateOptions: {
label: 'Foo',
placeholder: 'Foo'
}
}
];
vm.onSubmit = function() {
console.log(vm.fooModel)
}
// fooTemplate.html
<form ng-submit="vm.onSubmit()" novalidate>
<formly-form model="vm.fooModel" fields="vm.fooFields"></formly-form>
<button type="submit" class="btn btn-info submit-button">Submit</button>
</form>
I would prefer not to set the empty string as a default value for every single field.
A simple example can be found here