Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
960
Error : "cannot call methods on ... prior to initialization" due to onchange event triggered as page loads
posted

I have a scenario that is broken and need some help. My situation is this :

  1. All IG controls are initialized in the $(document).ready(function()
  2. HTML 'select' controls (which are linked to igCombo) have an 'onchange' function attached.
  3. This onchange function sets the 'readOnly' option of other IG controls based on its value.
  4. As the page loads, the onchange event is triggered BEFORE the document.ready function executes. I don't know why, but it does.
  5. This causes a "cannot call methods on igNumericEditor prior to initialization; attempted to call method 'option'" because the IG controls haven't been initialized yet.

How do I fix this? I have a few thoughts :

  1. Catch the exception and ignore it
  2. Set a global variable called INITIALIZED that onchange checks before it does any of these IG method calls
  3. Check if the control is an IG control (meaning its been initialized) before attempting these IG method calls

None of these are very elegant, but #3 would be the most robust solution. Is there another approach I should be using? If not, how do I perform the check in #3 above?

Thank you

Parents Reply Children
No Data