Closed chilversc closed 8 years ago
hey i try view the plnkr and it just work perfectly :smile:
You sure? You have to toggle busy on and off again. You'll note how in the after, although the form is visible the form does not contain any of the form fields and is listed as being valid despite the required field being blank.
"Invalid"
{
"$error": {
"required": [
{
"$validators": {},
"$asyncValidators": {},
"$parsers": [],
"$formatters": [
null
],
"$viewChangeListeners": [],
"$untouched": true,
"$touched": false,
"$pristine": true,
"$dirty": false,
"$valid": false,
"$invalid": true,
"$error": {
"required": true
},
"$name": "formly_1_input_name_0",
"$options": null
}
]
},
"$name": "formly_1",
"$dirty": false,
"$pristine": true,
"$valid": false,
"$invalid": true,
"$submitted": false,
"formly_1_input_name_0": {
"$validators": {},
"$asyncValidators": {},
"$parsers": [],
"$formatters": [
null
],
"$viewChangeListeners": [],
"$untouched": true,
"$touched": false,
"$pristine": true,
"$dirty": false,
"$valid": false,
"$invalid": true,
"$error": {
"required": true
},
"$name": "formly_1_input_name_0",
"$options": null
}
}
"Valid"
{
"$error": {},
"$name": "formly_1",
"$dirty": false,
"$pristine": true,
"$valid": true,
"$invalid": false,
"$submitted": false
}
This does not occur if you use:
<form name="vm.form">
<formly-form model="vm.model" fields="vm.fields"></formly-form>
</form>
So perhaps this should be a documented limitation if the goal is to move away from using <formly-form>
without an outer <form>
element.
Note that the problem still exists if you use <formly-form form="vm.form" root-el="form">
.
Although, it could still be a problem even when using <form>
if you want to reference different sections of a formly form. http://embed.plnkr.co/tmoPJtWvVOZ3eK0XbzHu/
I can make this work with the current form by assigning both the form
and the formly-form
to the same property:
<form name="vm.form">
<formly-form form="vm.form" model="vm.model" fields="vm.fields"></formly-form>
</form>
Although it works, something about it just feels wrong. Though it does now update the form variable correctly and works with the standard method of setting $submitted
to show field errors.
I can make this work with the current form by assigning both the form and the formly-form to the same property
This is how it's intended to work. You're basically passing the form to formly-form
telling it what to use for the NgFormCtrl
. Formly does some magic under the hood to manage the NgFormCtrl
to make the API more clear. Unfortunately that leads to issues like the one you're seeing, but most of the time it's better than the alternative.
I don't think there's anything I can do to fix this. Just name your form and pass it to formly-form
.
Steps to reproduce
ng-if
block.<formly-form form="vm.form">
ng-if
to hide the form.ng-if
to show the form.Expected result
The form should contain all its fields and show as invalid.
Actual result
vm.form
continues to refer to the old form that is now blank..Demo
View plnkr