I must admit I have yet to fully grasp the complexities of JSEvent and how exactly you can intercept different events in Solution Model and how you can get useful information from them. In a Solution Model form I need to know the name of a label when this is clicked and pass its name to a method.
This is my code:
var newLbl = oneFrm.newLabel("text",200,200,100,60);
var lblMt = onetFrm.newFormMethod('function onClick() { globals.mt_action(); }');
newLbl.onAction = lblMt;
I now want to pass the name of the label/button to the global method. I tried to use .getElementName but I don’t exactly understand how it works. In the Servoy Wiki example it shows
if (event.getElementName() == 'myElement')
{
elements[event.getElementName()].bgcolor = '#ff0000';
}
I really don’t understand what that “event” is and how do I define it.
Methods called from events on forms or elements can receive one or more predefined arguments, one of them being an argument containing a JSEvent object.
To see which arguments get send into which form/element event, create the method that you attach to the form/element event through double clicking the event property in the Properties view (for example: doubleclick the onAction property in the properties view when you have selected a button in your form editor).
When you create a method that way, Servoy automatically created a new method with all the parameters correctly setup + documentation.
Your code doesn’t define an ‘event’ parameter on the onclick method, so then you cannot access the JSEvent object by the name ‘event’. You could access it by the code ‘arguments[0]’ (for onAction events, the JSEvent object gets passed as the first argument), or change the onClick method, like:
onetFrm.newFormMethod('function onClick(event) {//Now you have access to the JSEvent object unde rthe name "event"; globals.mt_action(); }');
thank you very much for your prompt reply. Quite straightforward, but when you are stuck in a reasoning loop you never imagine that solutions are round the corner.