1
0
-1

I have a native component with a timer with two functions "start" and "stop". I already have the component working in my form, the problem is that I don´t know how to fire these methods inside the events for example a button click.

Do you know how can I access them?


  1. Howard Treisman

    Hi Fabiola

    Can you provide us a little more detail about what the component does, how it interacts with the time, and you want to do? Do you want to fire this method from a button that is part of the component itself, or from another button somewhere in the form?

    Thanks,

    Howard

CommentAdd your comment...

3 answers

  1.  
    2
    1
    0

    Hi,

    If you have written the native component, you should add rule helpers to enable the rule editor to add the code for you.

    In widget.json, setup the rule helpers like this:

    Then you can use the code in the rule editor:

    If you have no control over the native component to add the helpers, you should be able to call it using Form.getItemFromPath like the sample code in the rule helper, providing the method was added directly as a member function in the code.

      CommentAdd your comment...
    1.  
      1
      0
      -1

      If you have written your methods correctly, then the correct way to invoke them is: 

      Form.getItemFromPath('data.myComponent').myMethod();

      The rule helpers don't actually invoke the code - they are just there to make it easier for anyone who uses the code/rule editor in Maestro to know what the available methods are, and to insert code snippets into their code.

        CommentAdd your comment...
      1.  
        1
        0
        -1

        Hi bill,

        I tried to expose the start and stop functions using rule helpers as you sugested but it seems that rule helpers are some kind of pre written code that is copied to the editor when you click on them on the context menu. This is not helpful to us because the code inserted this way does not get updated.

        For example, lets say that i have 10 buttons across multiple forms using the following rule helper

        console.log('tick'); // <-- this is for debugging
        tick_count++;

        And then we notice that somebody forgot to remove that console log, we delete that line from the rule helper. When we run the form again the log is still there because it was copied in every single button that used it, so now we have to look for it in every form and delete it again.

        Is there a way to expose component functions so we can do something like timerComponent.start()?

        1. Unknown User (bfrost)

          Hi,

          You should be able to call your start method by:

              Form.getItemFromPath('data.timerComponent').start();


        CommentAdd your comment...