0

I'm trying to detect when all form elements on the page have been populated (including dropdowns), before triggering a function that initializes a plugin on those elements.

Right now I'm using a very ugly timeout function with a delay, but it obviously varies based on loading times. Also I have multiple controllers that are responsible for rendering out the various form fields on the page.

I tried calling the plugin after one of the render functions but there's still a variable delay from when the render occurs and the select boxes are populated.

I was thinking adding a ng-model on the < form > but how would I know when it's done populating?

So basically I want a reliable way for:

  1. The page loads ALL the form elements (including populated the select boxes)

  2. an event triggers which call my plugin

Seems like there should be an easy solution that I'm not aware of.

Thanks in advance.

brainmonger
  • 497
  • 1
  • 6
  • 17
  • If you put together a fiddle or plunker, it would be a lot easier to help you. It could me any number of things, or just a different way of thinking about the process. – Zack Argyle Aug 26 '14 at 00:10

1 Answers1

0

$evalAsync is your friend if you dont want to use timeout and you are trying to trigger a function after you got data back from your server...

To understand this better please watch this video and read this

Hope you find this usefull

Community
  • 1
  • 1
Ankit Ladhania
  • 1,005
  • 1
  • 12
  • 19
  • Hey, thanks for the reply. I'm able to detect when I receive data back from the service, but it takes an additional amount of time to populate that data into the form's various select dropdowns.. I was hoping there's a way to detect when all form elements are populated and only then trigger my function. – brainmonger Aug 26 '14 at 19:02
  • Warning this is a Hack. what you can do is that after each form element is filled call a function which counts the number of elements filled and when the # of elements match the total # of form elements then call the function you want to call at last. – Ankit Ladhania Aug 26 '14 at 19:07
  • The number of form elements could vary. Since I'm working on an enterprise scale application, I'm not sure this approached would be approved. hmm.. not sure why this is so difficult. I might be missing some angular function I don't know about yet. – brainmonger Aug 26 '14 at 20:26
  • do you know about `ng-submit` `ng-disable` `$error` these may help you read the docs. – Ankit Ladhania Aug 26 '14 at 20:46