cancel
Showing results for 
Search instead for 
Did you mean: 

Form controls javascript and messages

matthieulaborie
Champ in-the-making
Champ in-the-making
Hi,

We are developping a lot of form controls is there a way to include javascript and css only when the control are present in the form idem for i18n javascript keys ?

Today we are using 

<config>
      <forms>
         <dependencies>
            <css src="/modules/custom-autocomplete/autocomplete-ext.css" />
            <!– Spel editor –>
            <css src="/modules/spel-editor/spel-editor.css" />
            <css src="/modules/spel-editor/shThemeDefault.css" />
            <js src="/yui/editor/editor.js"/>
            <js src="/modules/spel-editor/spel-editor.js" />
            <js src="/modules/spel-editor/shCore.js" />
            <js src="/modules/spel-editor/shBrushJScript.js" />
            <!– Decision tree –>
            <css src="/components/form/controls/decision-tree.css" />
            <js src="/components/form/controls/decision-tree.js" />
                                …
         </dependencies>
      </forms>
   </config>


Which is include in all forms. I have try using :



<@markup id="css" >
   <@link rel="stylesheet" type="text/css" href="${url.context}/res/modules/spel-editor/spel-editor.css" group="form" />
   <@link rel="stylesheet" type="text/css" href="${url.context}/res/modules/spel-editor/shThemeDefault.css" group="form" />
</@>

<@markup id="js">
   <@script type="text/javascript" src="${url.context}/res/yui/editor/editor.js" group="form" />
   <@script type="text/javascript" src="${url.context}/res/modules/spel-editor/spel-editor.js" group="form" />
   <@script type="text/javascript" src="${url.context}/res/modules/spel-editor/shCore.js" group="form" />
   <@script type="text/javascript" src="${url.context}/res/modules/spel-editor/shBrushJScript.js" group="form" />
</@>



in my controls

But it doesn't work when the form appear under popup mode throwing

TypeError: SpelEditor  is not a constructor

SpelEditor is define under spel-editor.js

Regards

Matthieu
2 REPLIES 2

eamell
Champ in-the-making
Champ in-the-making
Unfortunately as far as I know the answer is no you can't do that.  I have looked into it a bit myself so let me give you my reason for thinking so.  The way Alfresco includes dynamic forms (like the popup controls) is to dynamically include the form when requested (which is exactly what you want).  When you do this script tags are not automatically executed so to ensure the scripts get executed Alfresco strips the script tags out of the generated HTML and executes the scripts.  Unfortunately this means that any objects or classes created in those scripts won't be available in the main context.

I wish I could remember where I found the code that does the stripping.  It was probably somewhere in alfresco.js but it could have been in form.js or form-runtime.js as well.

Hope this helps answer your question.

Thanks,

It answers my question, alfresco should consider refactoring it to make a bit more modular. Anyway if I want to achieved it I should remove the stripping codes or leave all the controls js's included in all my pages.

Regards