Aug 17, 2011, 3:23 PM
[CLOSED] cross-window form validation with focus on an invalid control
I have two windows:
- 1 that contains the ext form and its controls
- 1 that contains the action buttons, particularly 'Save'
Step to reproduce:
- enter something invalid in a combobox of the form
- click on 'save'
The combobox doesn't receive any 'blur' event and the validation passes.
I'm looking for a generic solution that would work for a form with any kind of ext controls in it.
My current best solution is to manually trigger a 'mousedown' event on the ext form.
Unfortunately, a delay is set in mousedown event handler in Ext.form.TriggerField.onFocus API:
this.doc.on('mousedown', this.mimicBlur, this, {delay: 10});
So it works only if I also put a timer (above 10) between the mousedown generated and the validation check.
Is there a better way to do it?
Is it possible to avoid the timer and asynchronous validation?
Form window:
Thanks
- 1 that contains the ext form and its controls
- 1 that contains the action buttons, particularly 'Save'
Step to reproduce:
- enter something invalid in a combobox of the form
- click on 'save'
The combobox doesn't receive any 'blur' event and the validation passes.
I'm looking for a generic solution that would work for a form with any kind of ext controls in it.
My current best solution is to manually trigger a 'mousedown' event on the ext form.
Unfortunately, a delay is set in mousedown event handler in Ext.form.TriggerField.onFocus API:
this.doc.on('mousedown', this.mimicBlur, this, {delay: 10});
So it works only if I also put a timer (above 10) between the mousedown generated and the validation check.
Is there a better way to do it?
Is it possible to avoid the timer and asynchronous validation?
Form window:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Form Validation from a different window</title>
<script language="javascript" type="text/javascript">
function isFormValid()
{
return frmMain.getForm().isValid();
}
</script>
</head>
<body>
<div>
<b>Validation passed although a field is invalid</b>
<ul>
<li>Enter something invalid in the combobox</li>
<li>Click Save</li>
</ul>
<form id="Form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:FormPanel ID="frmMain" runat="server">
<Items>
<ext:ComboBox ID='cb1' runat="server" AllowBlank="false" Text="first" >
<Items>
<ext:ListItem Text="aaa" Value="a" />
<ext:ListItem Text="bbb" Value="b" />
<ext:ListItem Text="ccc" Value="c" />
<ext:ListItem Text="ddd" Value="d" />
<ext:ListItem Text="eee" Value="e" />
</Items>
</ext:ComboBox>
<ext:ComboBox ID='cb2' runat="server" AllowBlank="false" Text="second">
<Items>
<ext:ListItem Text="aaa" Value="a" />
<ext:ListItem Text="bbb" Value="b" />
<ext:ListItem Text="ccc" Value="c" />
<ext:ListItem Text="ddd" Value="d" />
<ext:ListItem Text="eee" Value="e" />
</Items>
</ext:ComboBox>
</Items>
</ext:FormPanel>
</form>
<br />
Save Button is in another window:<br />
<iframe src="testbtn.aspx" height="50" width="100"></iframe>
</div>
</body>
</html>
Buttons window:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script language="javascript" type="text/javascript">
function clickSave()
{
// Is there a better way to do it without having to generate a onmousedown
// and performs an aynchrounous validation ?
window.parent.document.body.fireEvent('onmousedown');
window.setTimeout(check, 20);
}
function check()
{
alert(window.parent.isFormValid() ? "Form valid -> save OK" : "Form invalid-> save KO");
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<ext:FormPanel ID="frmBtn" runat="server">
<Items>
<ext:Button ID='btnSave' Text="Save" runat="server" OnClientClick="clickSave()"></ext:Button>
</Items>
</ext:FormPanel>
</div>
</form>
</body>
</html>
Thanks
Last edited by geoffrey.mcgill; Aug 23, 2011 at 7:30 PM.
Reason: [CLOSED]