2
1
0

Is there a way to declare a JavaScript function or library within a Maestro form, then reference it from other objects in the form? Or do we need to write the functions in a JS file and load it as an external resource?

    CommentAdd your comment...

    1 answer

    1.  
      2
      1
      0

      Hey Chris, there is a JavaScript Liibrary component in the palette that satisfies this requirement.

      1. Ben Warner

        Did this give you what you needed Chris?

      2. Chris Reid

        It lets us do what we need to do, I was asking more if there is a way to define these at a form level, without having to upload a library as a shared resource. I asked this question on behalf of a client, who like to define JS functions in each of their forms to handle common procedures. These would be unique to each form, so uploading them as shared resources (correct me if I'm wrong, but this seems to be how the JavaScript Library component) would be functional, but perhaps not the most elegant solution.

      3. Ben Warner

        I'm not clear on what you are saying. The JavaScript Library does not have to be a shared resource, just add it to the form you want it on...

      4. Chris Reid

        Ah, ok, I assumed that when you uploaded a library to the component it would go to a shared library. I've had a play now and I can see it on the form's resources tab, with the option to publish to another library. This is perfect, thanks Ben.

      5. Sacha Trube

        Hey Ben, Does it matter where you place a JavaScript Library component within the structure?

        Maestro won't let me add it to the "Content" level, where I assume it should go, with an error "Can't place a JavaScript Library in a Page Controller".

        Although I can add it to a page, it just doesn't seem right that it should go there.

         

      6. Matthew White

        I was about to ask the same question and after researching how it works in Maestro and reviewing this answer I think that this solution goes a long way to solving my problem. However, I would really like to completely divorce form specific javascript "libraries" from an associated resource and it's backing as a local file. In other words I just want a place to put form specific global functions in Maestro for a given form and edit them in maestro. Otherwise if someone else wants to edit the form and make changes to the function they have to export the resource, edit it in their local editor and upload it.

        It's not clear to me whether this javascript resource is global to all versions of the form or bound to a specific version? If I change the javascript library content will it potentially break old versions?

      7. Matthew White

        The context for my comment is the scenario where I have some logic in a visibility rule for a block in a form and then I realise I'm duplicating it in another block and maybe a third. It would be handy to on the spot create a function (within the Maestro editor) that they can all call without the overhead of creating and maintaining a library and potential version problems. 

      CommentAdd your comment...