Categories
XPages

In XPages you can add an id to an event handler and call it from CSJS.

Ok let’s get this out of the way.  I’m going to talk about Client Side JavaScript and that’s WAY out of my comfort zone on a good day.  But I had a need to work with it and the amazing Declan Lynch came to the rescue.

I want to make a NotesIn9 about this when I can but as I’m crushed with work I just don’t know when that might be so here’s my attempt at blogging some technical information.  🙂

Today I had the need to use client side java script to trigger the existing event of an editbox control.

I didn’t want to run a function, I didn’t want to trigger a partial refresh directly, I wanted to trigger an event on a component from csjs.

<xp:inputText id=“myInputBox”  value=“#{viewScope.vsMyValue}”>

<xp:eventHandler id=“MyEvent” event=“onkeypress” submit=“true” refreshMode=“partial” refreshId=“#{javascript:compositeData.refreshTarget}”>

<xp:this.action><![CDATA[#{javascript:controller.processSomething(viewScope.get(“vsMyValue”));

}]]></xp:this.action>

</xp:eventHandler>

</xp:inputText>

So that’s what the <xp:inputText> might look like.  The key to everything here is you can manually add an id to the <xp:eventHandler> and then target it!!

What I needed was the XSP.fireEvent

XSP.fireEvent(“keypress”,”#{id:MyEvent}”,”#{id:myInputBox}”,null,true);

Worked like a charm.

XSP.fireEvent(evt, clientId, targetId, clientSideScriptName, submit, valmode, execId) Allows to trigger an event script

Note that this fireEvent MIGHT be unsupported.  It seems to be as of 2013 from this StackOverFlow question :  http://stackoverflow.com/questions/16964469/how-to-use-xsp-fireevent

In this case the targetId is the name of the id I added to the event handler.

That’s pretty much all I know.  Seems to work great but I’ll know more tomorrow.  

I hope this might be helpful to someone.