How to add custom events to subclasses

I’m working on a subclasses of the built-in WE controls. Now I want to implement certain events that are not yet there. On the JS side I suppose I’d have to catch the events using event listeners. But how can I further proceed within Xojo, given the fact that the “ExecuteEvent” Event is WebControlWrapper only (which I am not using here)?

If you are using the native WE controls, implementing a new event is a simple as adding an Event Definition to the subclassed control (e.g. MyNewEvent) and then using RaiseEvent MyNewEvent when you need to. I do this all the time so I’m not sure why you need Javascript.

In my particular case, I want to subclass the Weblistbox and adding the possibility to have checkboxes in a cell. Cells can be altered using the .innerHTML property, so that’s not the problem. Rather tricky, I need to catch the “Change” event when a user checks/unchecks the checkbox. In JS I’d catch the “onChange” event, send it to the App using “Xojo.triggerServerEvent” but I cannot catch it from there?

Ah, sorry. You didn’t indicate exactly what you were trying to do. That’s beyond my knowledge.

You might want to check out the Taylor Design WebControls at http://webcustomcontrols.com. Not sure if he’s got checkboxes working in his WebListbox but if not, I’d contact him to see what he thinks on how hard it is to add.

I too need to find a way for Javascript to trigger events on subclassed controls. Is this possible? I want to add “touch” events to some of the default controls to better support tablet users, but currently it seems only the WebCustomControls support triggering extraneous events.

Anyone know how to do this?

Would be awesome if they would could get the .TriggerEvent method to be used and ‘userdata’ passed to a custom ‘Event Definition’.

I’m wondering if this could be implemented with a single WebCustomControl and some introspection… Granted the framework should really support something like this.

I’m researching what I can break now, actually… we’ll see. :wink:

Don’t let Greg hear you say that… :stuck_out_tongue:

If you hack, you are responsible for your hacks. But what are you actually trying to accomplish? Sounds like you’re going down a road you don’t have to go down.

Hahaha… in a way that doesn’t edit or change the framework, of course. :slight_smile:

Personally I need want to add additional javascript events on subclassed WebControls so that they trigger the corresponding serverside event. For example I want to add the TouchStart events to some controls:

documentControlHere.addEventListener(‘touchstart’, someXojoFunction(), false);

But I want to the someXojoFunction() to be one that raises a custom event on the subClassed Control.
Currently only the WebControlWrapper has a way to support this but I want to add events to regular controls.

I am not sure, and may be I’m too late, but can’t you somehow implement Xojo.triggerServerEvent? Which allows you to define event on your choice and use the same event handler with select case and passes array of params from the page, called one.

You can find usage in WebControlWrapper SDK manual. It’s in the EXTRAS folder.

Be aware that the fact that the WebSDK JavaScript methods always render in the framework is a bug. When that gets fixed, they will only render if a WebControlWrapper subclass is used in your project.

Greg,

Do you know are there any plans to add “ExecuteEvent” on the built in controls like the WebControlWrapper? This would make it really easy to add additional events to the built in controls. I mean we can always create a WebControlWrapper that ends up wrapping to another control on the page but this is a lot more work to implement.

Having this would allow users to simply call execute javascript to write in an additional eventImplementation and have the executeEvent method implemented on the control. Otherwise we would have to have the WebControlWrapper try and track down the proper control, as well as remember to drag this into the page every time we include a control that needs it and tie them together.

There are no plans to do this at this time, however you could file a feature request. :slight_smile:

I added a feature request if anyone would like to put some points down.

(https://xojo.com/issue/30767)]Case
<https://xojo.com/issue/30767>

I definitely wish we could support more than 5 cases… 5 per category seems more adequate.