angular-dynamic-forms icon indicating copy to clipboard operation
angular-dynamic-forms copied to clipboard

Add form fields dynamically

Open dearlordylord opened this issue 10 years ago • 15 comments

Hey,

it would be great to have possibility adding fields dynamically from code. Currently I don't see such functionality in source. It would be even better to have dynamic adding of another nested forms through template modifying. I could take this task on myself if you'd like.

dearlordylord avatar Apr 10 '14 07:04 dearlordylord

It should already have dynamic element add/remove, as that was one of my design goals starting out, but I don't recall testing it... This is indeed essential.

As for subforms, I intend to support such nesting in a future version (see #4), and the dynamic add/remove should cover this part of the request adequately at that point.

danhunsaker avatar Apr 10 '14 07:04 danhunsaker

With fieldset support in place, we have an option for supporting subforms. I'll tackle dynamic add/remove (via updating the template, of course) after addressing #3, which should be relatively quick.

danhunsaker avatar Apr 25 '14 09:04 danhunsaker

Thank you for a great directive! Maybe it's just me, but is it true, that the DOM is not updated if the JSON template for the form is? That would be a really great feature, as the forms are then in fact dynamic. :)

stumpdk avatar May 08 '14 21:05 stumpdk

Yes, I haven't gotten that finished, yet. Hoping to sometime this weekend, though.

danhunsaker avatar May 08 '14 21:05 danhunsaker

That sounds really good. If, let's say a select box options are changed, is it possible to silent update the form without "redrawing" it from scratch?

stumpdk avatar May 09 '14 06:05 stumpdk

That's the hard part, and why it's not already in place. I really want to avoid changing anything in the DOM that doesn't need to be, but that means inspecting the changes and seeing what they are actually comprised of.

danhunsaker avatar May 09 '14 07:05 danhunsaker

Such a solution sounds really nice! I'm looking forward to the implementation. If you need help with implementation or test, I can help you with that.

stumpdk avatar May 09 '14 09:05 stumpdk

As I see it, there are two solutions to this challenge (correct me if I'm wrong):

  1. Use $watch to check for changes in the JSON-object. Then traverse through the objects and check which ones have changed, and what did change. Update the corresponding element in the DOM.
  2. Use the same procedure as above, but handling every form-element as its's own would make it easier to update parts of the form instead of it all.

stumpdk avatar May 12 '14 14:05 stumpdk

That's the plan, yes. The trick is keeping track of which DOM element corresponds with which template item. The code will need to be refactored some to make this work properly. I'll be working on this today.

danhunsaker avatar May 12 '14 17:05 danhunsaker

Any progress update on this @danhunsaker? I was about to dig into the code and trying to add this feature when I found this issue. Support for this is critical for my use case, so I'd be happy to help if needed/useful.

kynan avatar May 16 '14 19:05 kynan

I hope to work on it some tomorrow, when I have time allocated to it. Hopefully nothing will come up to prevent that, like it has the past several weeks. :(

danhunsaker avatar Jun 19 '14 21:06 danhunsaker

Hi Dan,

Thanks for this module, it's really useful. We are also interested to add form fields dynamically. It seems that you have been busy and had no time yet. Can you suggest a workaround in the meantime?

It would be great to use your module for our APP, but we absolutely need to add form fields dynamically.

Thank you!

RazvanMihaiu avatar Jun 27 '14 10:06 RazvanMihaiu

Continued apologies to everyone for not getting this done. I've had some trouble getting it to work properly, so some help would be appreciated. (I've also had some trouble finding the time to write code lately, so the same applies for that reason as well...) Otherwise, I'll keep hacking away when I have bits of time to do so.

danhunsaker avatar Nov 11 '14 14:11 danhunsaker

Any news on this topic?

acesaft avatar Mar 25 '15 05:03 acesaft

Nothing to report beyond the "I don't have the time right now" in my previous comment. You may have better luck with one of the projects listed in the README as alternatives. Apologies again for not working on this, but unless someone wants to pay for the time I spend on it (the only way I was able to get it this far), I simply won't be able to do more for the foreseeable future.

danhunsaker avatar Mar 25 '15 09:03 danhunsaker