-
Notifications
You must be signed in to change notification settings - Fork 27.4k
Input validity reflected on form after $removeControl
#12263
Comments
It's definitely unexpected and broken from this perspective. That said, removing the control without actually removing the input is not something that's best practive. Can you share the scenario in which you need this? |
My particular scenario is that I need to have the field not be validated in any way under certain circumstances. I have a directive that evaluates an expression and determines to whether to add or remove the control from the form. It seemed easier than messing with the validate pipeline (and possibly parsers pipeline.) I couldn't find a way to not validate fields besides actually removing the field from the DOM, which wasn't an option. |
The best solution I've found so far is to change the 'type' of the input to an unsupported value. This should preclude it from constraint validation, yet still leave it as submit-able. The 'hidden' type works like this, but with the addition of preventing render. It's standard behavior for an input of an unknown type to render as a text input. Since willValidate() isn't called until the submit happens, it should be fine to change the type value all you need before submitting. HTML5 Constraints Validation API |
FWIW, I believe removing the control is a valid usecase (albeit uncommon) and should be supported. @Narretz (since you are an |
After looking into it a bit, we don't seem to properly support adding or removing controls after the initialization phase, although we provide Basically, Essentially, there doesn't seem to be provision for re-assigning IMO, it would make more sense to (also) provide add/remove methods on the control itself. They would take care of internal stuff and also call the |
@gkalpak I think you are quite right. Basically, $removeControl assumes that the removed control is actually completely removed from the UI (like when it's called from the $destroy event), so the cleanup doesn't have to deal with the child control. |
Otherwise, once the removed control's validity changes, it will continue to be reflected on its former parent form. Fixes angular#12263
Otherwise, once the removed control's validity changes, it will continue to be reflected on its former parent form. Fixes angular#12263
Otherwise, once the removed control's validity changes, it will continue to be reflected on its former parent form. Fixes angular#12263
Otherwise, once the removed control's validity changes, it will continue to be reflected on its former parent form. Fixes angular#12263
Otherwise, once the removed control's validity changes, it will continue to be reflected on its former parent form. Fixes angular#12263
This fixes cases where the control gets removed, but the control's element stays in the DOM. Previously, if the removed control's validity changed, a reference to it would again be stored on its former parent form. Fixes angular#12263
This fixes cases where the control gets removed, but the control's element stays in the DOM. Previously, if the removed control's validity changed, a reference to it would again be stored on its former parent form. Fixes angular#12263
This fixes cases where the control gets removed, but the control's element stays in the DOM. Previously, if the removed control's validity changed, a reference to it would again be stored on its former parent form. Fixes angular#12263
This fixes cases where the control gets removed, but the control's element stays in the DOM. Previously, if the removed control's validity changed, a reference to it would again be stored on its former parent form. Fixes angular#12263
This fixes cases where the control gets removed, but the control's element stays in the DOM. Previously, if the removed control's validity changed, a reference to it would again be stored on its former parent form. Fixes angular#12263
This fixes cases where the control gets removed, but the control's element stays in the DOM. Previously, if the removed control's validity changed, a reference to it would again be stored on its former parent form. Fixes #12263
After removing a field from a form using
$removeControl
, if you change the field's value [to be invalid] it will affect the validity of the form it was removed from.Not too sure if this is working as expected or not, but seems to be undesired.
Affected versions [at least] 1.3.x, 1.4.x
Steps to reproduce (given the following plnkr)
http://plnkr.co/edit/NZJn0zwWdKxvrIlQxUmn?p=preview
$removeControl(...)
For step 6 I would expect the form to no longer be affected by the field, especially since step 4 set the form to valid when the invalid field was removed.
The text was updated successfully, but these errors were encountered: