Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dynamic form fields #32

Open
bbodenmiller opened this issue Nov 6, 2015 · 11 comments
Open

Add support for dynamic form fields #32

bbodenmiller opened this issue Nov 6, 2015 · 11 comments

Comments

@bbodenmiller
Copy link

I'm attempting to add new form fields (checkboxes) to a form using ngRepeat and have this mark the form as modified. A bit hard to explain but try selecting the Add new at http://plnkr.co/edit/TSjSAI2E3FwJHg75Y5Hv?p=preview and see that the form is not marked as modified.

Looks related to #12.

@bbodenmiller bbodenmiller changed the title not detecting new form fields as modified not detecting add/remove form fields as modified Nov 6, 2015
@bbodenmiller
Copy link
Author

Same with the deleting of form fields... try the Delete first button on http://plnkr.co/edit/TSjSAI2E3FwJHg75Y5Hv?p=preview as well.

@slavafomin
Copy link
Member

Hello @bbodenmiller!

Thank you for your interest in this module. However, you've forgot to mention that you are using a third-party module for list of checkboxes. Angular Input Modified is built around standard ngModel directive and strictly conforms to it's public interface. That makes it compatible with all other input plugins, that also implement the ngModel API.

I can't say exactly what the problem is, I don't have much time right now for investigation, but it looks like this issue should be looked into by developers of checklist-model. @beradrian do you have any thoughts on this?

Thanks!

@bbodenmiller
Copy link
Author

Hi @slavafomin thanks for looking into this. I am able to replicate this without a third-party module at http://plnkr.co/edit/l10QsL17GrQROVewd28x?p=preview using the Delete First button. Any thoughts on potential solutions or areas to look into? Thanks.

@ggaltqq
Copy link

ggaltqq commented Dec 24, 2015

Hi. Got same problem.
Example from your demos with adding, deleting items from collection
http://jsfiddle.net/4kxmn4Lx/

@slavafomin
Copy link
Member

Hello! Thank you for an update on this issue.
I will try to look into this on first occasion.

@eldo-xy
Copy link

eldo-xy commented Apr 18, 2016

Is there any update on this? It would be very helpful if adding/removing an item to a collection flagged it as modified.

@slavafomin
Copy link
Member

This module is working around ngModel directive. In the example above, ngModel points not to the collection, but to the element of the collection, therefore it watches the element for changes and not the collection itself. You should be able to watch the collection manually using $scope.$watch function. I'm not sure it should be handled by this module.

However, if you have ideas of how it could be implemented, I'm open for discussions ;)

@yingqiaoflick
Copy link

yingqiaoflick commented Oct 21, 2016

We run into the similar issue. Then, we found out that adding/deleting an ngModel after a form has been initialized won't trigger the inputModified.formChanged event. Is it a way we could fire the event? Will it solve the problem and keep the features of this package?

@akoppela
Copy link

akoppela commented Nov 1, 2016

We have the same issue. Would be nice if you add support for dynamic fields.

@slavafomin slavafomin changed the title not detecting add/remove form fields as modified Add support for dynamic form fields Feb 21, 2017
@jrharshath
Copy link

jrharshath commented Apr 26, 2017

We're having a similar issue. I've put together a plunker to demonstrate the issue in the simplest form possible.

1. Adding new elements to a form does not mark it modified
I understand that when new elements are added, the masterValue of that input's ngModel is set to its initial value . By that logic, that input is indeed not in a modified state when it first appears, and by extension, the form is not modified either.

2. Removing existing elements does not update the modified flag.
For example, let's say there are two inputs in a form and one of them is modified. At this point, the form's modified flag is true. Removing the modified input does not cause the form's modified flag to become false - however, this may or may not be desirable in most use cases.

--
It is often the case that an input is added because of a change to a complex object. Conversely, form elements may be deleted when a change happens to that same object. The form's modified state is mostly likely being used as a proxy for that object's modified state.

What that is the use pattern, it is desirable to set the form's modified flag to true if that form no longer has the same inputs that it started off with. Perhaps this behaviour could be toggled on my adding a flag to the ngForm. What do you think?

@slavafomin
Copy link
Member

Thank you everyone for pointing out your issues. However, I see different use cases and different problems mentioned. Could someone reduce everything being said here to a concrete proposition and/or algorithm?

The module wasn't designed for dynamic forms initially, so there could be problems with it. Right now we have the following rules:

1). Form's modification state is controlled by modification state of all children forms and models.

2). Model's modification state is determined by it's current value and it's equality to the master value.

3). The master value is determined when control is created or when it's manually marked as pristine.

So the proposition should take into account above rules. Especially, if you have cases where the rules are not respected for some reason (we should consider such cases as bugs and fix them as a first priority).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants