XPages - how to move cursor to a specific editable field?

Does anyone know if it is possible using SSJS to move the cursor to a specific Editable Field of an XPage, please?

Thanks. Jerry.

Subject: Re: Move cursor to field in SSJS

I’ve not found a way, I can’t se any methods under getComponent that would work. Technically I guess you need to set something in SSJS that can be picked up by a client-side function, but I haven’t got my head around how that could be done.

I noticed this morning on the XPages Blog that there will be client-side events for partial updates in 8.5.1, so you will be able to trigger a partial update and onComplete, use client-side javascript to set focus to the relevant field. I haven’t seen 8.5.1 yet to try, but hopefully it should be out in the next month.

Regards

Paul

Subject: Re: move cursor to field in SSJS

Thanks for your response Paul.

Yes, I’m sure there must be somthing in Dojo that could help, but as yet I’ve not had any chance to apply my brain to it. E.g.

var e = this.getElementById(clientId);

if(e!=null) {

e.select();

which can be found in …

http://www-10.lotus.com/ldd/ddwiki.nsf/dx/Client_Side_JavaScript_Libraries_in_XPages.htm

Subject: Here’s an example

It’s not as straightforward as setting a property, but I could not find anything either. I use a script block to generate the clientside JS which includes SS JS sessionScope variables. The button sets the sessionScope to the field id, and when the page is reloaded the scriptblock regenerates the JS to set the focus.

<?xml version="1.0" encoding="UTF-8"?>

<xp:view xmlns:xp=“http://www.ibm.com/xsp/core”>

<xp:table>

	<xp:tr>

		<xp:td>field 1</xp:td>

		<xp:td>

			<xp:inputText id="inputText1"></xp:inputText></xp:td>

	</xp:tr>

	<xp:tr>

		<xp:td>field 2</xp:td>

		<xp:td>

			<xp:inputText id="inputText2"></xp:inputText></xp:td>

	</xp:tr>

	<xp:tr>

		<xp:td>field 3</xp:td>

		<xp:td>

			<xp:inputText id="inputText3"></xp:inputText></xp:td>

	</xp:tr>

	<xp:tr>

		<xp:td></xp:td>

		<xp:td>

			<xp:button value="Set Focus To field 2" id="button1">

				<xp:eventHandler event="onclick" submit="true"

					refreshMode="complete">

					<xp:this.action><![CDATA[#{javascript:sessionScope.focusFieldName=getClientId("inputText2");}]]></xp:this.action>

				</xp:eventHandler></xp:button></xp:td>

	</xp:tr>

</xp:table>

<xp:scriptBlock id="scriptBlock1">

xp:this.value<![CDATA[theField=‘#{sessionScope.focusFieldName}’;

if (theField>‘’){

document.getElementById(theField).focus();

}

]]></xp:this.value>

</xp:scriptBlock>

</xp:view>

Subject: Re: Here’s an example

Thanks - you’re a star.

I’ve never come across a ScriptBlock before, double Thanks!

Cheers. Jerry.

Subject: The Scriptblock control

Jerry,

You can add a script block control by clicking Other and drag it to your XPage, the select Other Controls->Output Script.

Under the All properties you enter the code by selecting the value property and then compute value. Then for client side JS select “Custom” for the language. you can just type your code in there.

The reason you need it is that you can only compute serverside JS in client side JS using some sort of control to do the substitution. So it’s either a script block or computed field. With computed fields you need to add in “” tags etc.,. so the script block is easier.

Now with that said…this control is a pain to work with after you entered your code! The only way I can edit the code is to go into the source code. Hopefully it’s been fixed in 8.5.1.(I haven’t looked)

-John