Page 1 of 1

Adding a newly made method to a keyListener

PostPosted: Mon Apr 20, 2020 3:16 pm
by mees
Hi all,

I am currently making a function that creates keylisteners and callbacks on the fly, and adds them to an element. I've got it all working, except for one thing: I cannot get the addKeyListener method to recognize my new method correctly. The code to do so seems to be quite simple:

Code: Select all
         /** @type {JSMethod} */
         var method = solutionForm.newMethod(methodCode);
         plugins.keyListener.addKeyListener('keyListener_' + elementName, method, true);


The first call creates a function called onKeyTxtTest for me. This works properly. It's the second line that doesn't function propertly. If I use the code
Code: Select all
         /** @type {JSMethod} */
         var method = solutionForm.newMethod(splitCode.join('\n'));
         plugins.keyListener.addKeyListener('keyListener_' + elementName, onKeyTxtTest, true);

everything works as intended. So how do i get the addKeyListener-function to recognize my method? I tried
Code: Select all
         plugins.keyListener.addKeyListener('keyListener_' + elementName, method.getUUID(), true);
         plugins.keyListener.addKeyListener('keyListener_' + elementName, method.getName(), true);


But both to no avail.

Re: Adding a newly made method to a keyListener

PostPosted: Mon Apr 20, 2020 5:14 pm
by mboegem
Hi Mees,

the addKeyListener function expects the callbackFunction as a reference to the function.

So if you created the method on form 'myForm' this should work:
Code: Select all
plugins.keyListener.addKeyListener('keyListener_' + elementName, forms.myForm[method.getName()], true);


Hope that helps.

Re: Adding a newly made method to a keyListener

PostPosted: Tue Apr 21, 2020 8:23 am
by mees
That did the trick, thank you very much Marc!