Including a script in a module & then disabling the module, avoiding problems

Topics: Writing modules
Mar 15, 2012 at 11:28 AM

I'm wondering what's the best way to deal with this situation:

  1. include a script in the editor template for a part that's in my module (the script has been defined in the module's ResourceManifest)
  2. attach that part to the User, now when I edit the user, the script is active (it's jQuery.validate to be specific)
  3. disable the module - but the part is still attached to the user
  4. edit a user - boom!  ("A 'script' named 'jQuery.validate' could not be found.")

So, how to protect the website of the poor person who tries out my module & then disables it.  Is there a way to safely include scripts in editor-templates, or would I have to somehow try to extricate the part from the user on disable of the module.  That option sounds messy to me, as I guess generally in Orchard we don't try to completely back out of changes that modules have made when we disable them.  Or maybe I'm doing something wrong!

Coordinator
Mar 17, 2012 at 9:05 PM

But if your module is disabled, the driver should never run so how can the script still be included?

Mar 19, 2012 at 11:41 PM

False alarm and another learning experience :-)

Disabling the module does infact disable the part's editor template defined in the module, even though the part is still active and attached to the user.  There is no error.

It turned out I had another theme enabled (but not current) which was causing the problem.  So I've learnt 2 things - more than one theme can be enabled at one time (didn't know that!).  Along the way I've also got to know Script.Include & Script.Require.