-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi,
I've been receiving an ample amount of help from this community
especially when it comes from migrating from ZK3 to ZK5 issues.
I would like to ask for another help with this issue i am currently facing.
---------------------------------------------------------
I encounter a problem using jquery, although i've already found a work around.
but i am thinking maybe the problem is in my code, so i am hoping you could help me fix it.
I am using jquery to validate and display messages on the client side..
the problem comes when i am using a window pop-up form...
it seems that the jquery is not invalidating the form even if i already invoked it, instead
it adds another component to the widget so as making it an array of widget..
the codes are here as follows:
<?page title="Auto Generated index.zul"?> <zk> <window title="Hello World!!" border="normal" width="200px" apply="test.IndexCtrl"> <panel> <panelchildren> <script type="text/javascript"> <![CDATA[ function showError(widget, msg) { var html = "<div ><span>*"+ msg +"</span></div>"; jq(widget[widget.length-1]).after(html); console.log(widget); } ]]> </script> <button id="btnShow" label="Show Window" /> </panelchildren> </panel> </window> </zk>
package test; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.SuspendNotAllowedException; import org.zkoss.zk.ui.util.Clients; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Window; public class IndexCtrl extends GenericForwardComposer { /** * */ private static final long serialVersionUID = -9200331251694400936L; public void onClick$btnShow() { try { Window winForm = (Window) Executions.getCurrent().createComponents( "/window.zul", null, null); winForm.invalidate(); winForm.doModal(); winForm.detach(); winForm=null; } catch (SuspendNotAllowedException e) { Clients.clearBusy(); e.printStackTrace(); } catch (InterruptedException e) { Clients.clearBusy(); e.printStackTrace(); } catch (Exception e) { Clients.clearBusy(); e.printStackTrace(); } } }
<?page title="new page title" contentType="text/html;charset=UTF-8"?> <zk> <window id="windowForm" title="new page title" width="400px" border="normal" apply="test.WindowCtrl"> <grid> <columns> <column width="20%" /> <column /> </columns> <rows> <row> <label value="Firstname" /> <textbox id="txtFirstName" width="99%" /> </row> <row> <label value="Latname" /> <textbox id="txtLastName" width="99%" /> </row> <row> <button id="btnOk" label="OK" /> <button id="btnCancel" label="Cancel" /> </row> </rows> </grid> </window> </zk>
package test; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.util.Clients; import org.zkoss.zk.ui.util.GenericForwardComposer; import org.zkoss.zul.Textbox; import org.zkoss.zul.Window; public class WindowCtrl extends GenericForwardComposer { private static final long serialVersionUID = -1374098330647731875L; private Window windowForm; private Textbox txtFirstName; private Textbox txtLastName; public void doAfterCompose(Component comp) throws Exception { super.doAfterCompose(comp); windowForm.setTitle("Please enter your name"); } public void onClick$btnOk() { String msg = ""; if(txtFirstName.getText().trim().length()==0) { msg += " showError(jq('$txtFirstName'), 'Firstname is mandatory.');"; } if(txtLastName.getText().trim().length()==0) { msg += " showError(jq('$txtLastName'), 'Lastname is mandatory.');"; } if(msg.trim().length()>0) { Clients.evalJavaScript(msg); } else { Clients.evalJavaScript("alert('Hello " + txtFirstName.getText().trim() + " " + txtLastName.getText().trim() + "');"); windowForm.detach(); } System.out.println(msg); } public void onClick$btnCancel() { windowForm.detach(); } }
You can check the firefox console and notice that whenever you reload the window the next time,
it adds the new widget at the end of the widget array...
like this
[null, null, input#z_d__c1.z-textbox] [null, null, input#z_d__f1.z-textbox]
that's why my workaround is using this piece of code
jq(widget[widget.length-1])
before appending the error message or even validating the component in the client
but i was hoping to achieve the same result using only this code
jq(widget)
by the way i am using ZK 5.0.2
hope you help me again
many thanks,
Hi,
does nobody here face the same problem?
thanks
Hi all,
Is this considered a bug,
or is it my code, or its just the way ZK 5 behaves for window components...
thanks,
Hi,
I test with your example, and it works well.
Please use the latest ZK 5.0.3-FL to give it a try, which can be found - http://www.zkoss.org/download/freshly/
Hi jumperchen,
I'll give it a try, then i'll let you know.
thanks
Asked: 2010-05-26 01:38:32 +0800
Seen: 850 times
Last updated: Jun 02 '10