xpages - Set field focus after validation in dialog (Extension Library Dialog) -
i have following dialog, password field focus set when dialog has focus works when first loaded, want set password field focus when passwords don't match (i.e. after clicking ok button , running ssjs).
<xe:dialog id="dialogconfirmpassword" title="confirm password"> <xe:dialogcontent id="dialogconfirmpasswordcontent"> <xp:messages id="messagesconfirmpassword" layout="table" /> <xp:table style="width:100%" id="tableconfirmpassword"> <xp:tr> <xp:td> <xp:label value="password" id="lblpassword" for="confirmpassword" /> </xp:td> <xp:td> <xp:inputtext id="confirmpassword" password="true"> </xp:inputtext> </xp:td> </xp:tr> </xp:table> </xe:dialogcontent> <xe:dialogbuttonbar id="dialogbuttonbarconfirmpassword"> <xp:button value="ok" id="btnconfirmpasswordok"> <xp:eventhandler event="onclick" submit="true" refreshmode="complete"> <xp:this.action> <xp:actiongroup> <xp:executescript> <xp:this.script><![cdata[#{javascript:try{ var confirmpassword:string = getcomponent("confirmpassword").getvalueasstring(); if (session.verifypassword(confirmpassword, httppassword)){ /* runs notes agent */ getcomponent('dialogconfirmpassword').hide(); return true; } else { facescontext.addmessage("messagesconfirmpassword", new javax.faces.application.facesmessage("you have entered incorrect password, please try again.") ); /* want set focus password field */ return false; } } catch (e) { facescontext.addmessage("messagesconfirmpassword", new javax.faces.application.facesmessage("error! " + e.tostring()) ) return false; }}]]></xp:this.script> </xp:executescript> </xp:actiongroup> </xp:this.action> </xp:eventhandler> </xp:button> </xe:dialogbuttonbar> <xp:eventhandler event="onfocus" submit="false"> <xe:this.script><![cdata[dijit.byid("dialogconfirmpassword").focus();]]></xe:this.script> </xp:eventhandler> </xe:dialog> can set password field focus after setting facescontext.addmessage or way?
update: following output script worked:
<xp:scriptblock id="scriptblockconfirmpassword"> <xp:this.value><![cdata[#{javascript: if(viewscope.pwdsuccess === null) { return ""; }; var result = "dojo.byid(\""; result += getcomponent("confirmpassword").getclientid(facescontext); result += "\").focus();"; return result;}]]></xp:this.value> </xp:scriptblock>
a few pointers:
- don't go after components
getcomponent("confirmpassword")bind component scope variable, makes better code - you can't directly run client javascript action in ssjs (where indicated)
- your event handler never works since xpages id different clientside id
- a outputscript can solve challenge
so modify code (only essentials here):
<xp:inputtext id="confirmpassword" password="true" value="#{viewscope.confirmpwd}"> </xp:inputtext> <xp:button value="ok" id="btnconfirmpasswordok"> <xp:eventhandler event="onclick" submit="true" refreshmode="complete"> <xp:this.action> <xp:actiongroup> <xp:executescript> <xp:this.script><![cdata[#{javascript:try{ viewscope.pwdsuccess = session.verifypassword(viewscope.confirmpwd, httppassword); if (viewscope.pwdsuccess){ /* runs notes agent */ getcomponent('dialogconfirmpassword').hide(); } else { facescontext.addmessage("messagesconfirmpassword", new javax.faces.application.facesmessage("you have entered incorrect password, please try again.") ); } } catch (e) { facescontext.addmessage("messagesconfirmpassword", new javax.faces.application.facesmessage("error! " + e.tostring()) ); viewscope.pwdsuccess = false; } return viewscope.pwdsuccess }]]></xp:this.script> </xp:executescript> </xp:actiongroup> </xp:this.action> </xp:eventhandler> </xp:button> <xp:outputscript> <this.value><!cdata[#{javascript:if(viewscope.pwdsuccess) {return "";}; var result = "dijit.byid(\""; result += getcomponent("confirmpassword").getclientid(); result += "\").focus();"; return result; }]]</this.value> </xp:outputscript> (typed off head - contain errors). let know how goes.
Comments
Post a Comment