问题
I have a button,I want to form validation(client side) before direct click event fire.I tryed lots of way but failed.
** I already set textbox like this.
<ext:TextField ID="Ad" runat="server" FieldLabel="Dem ad" Flex="1" AllowBlank="false" CausesValidation="true"> </ext:TextField>
but still fire direct even before textbox checking
<ext:Button ID="Button1" runat="server" Text="save" Icon="Disk">
<DirectEvents>
<Click OnEvent="Dem">
<Confirmation ConfirmRequest="true" Title="Title" Message="are u sure you want to update..." />
</Click>
</DirectEvents>
</ext:Button>
回答1:
There is a few options.
You can return false from a DirectEvent's Before handler or from the same Listener.
protected void Submit(object sender, DirectEventArgs e) { X.Msg.Alert("Submit", "Submitted").Show(); }Ext.NET v2 Example
<ext:FormPanel ID="FormPanel1" runat="server"> <Items> <ext:TextField runat="server" AllowBlank="false" /> </Items> </ext:FormPanel> <ext:Button runat="server" Text="Submit"> <%--<Listeners> <Click Handler="return false;" /> it has the same effect as returning false from a DirectEvent's Before. </Listeners>--%> <DirectEvents> <Click OnEvent="Submit" Before="return App.FormPanel1.isValid();" /> </DirectEvents> </ext:Button> </form>
Another approach is using FormBind. It automatically disables a component if a FormPanel is invalid. A component should belong to a FormPanel.
protected void Submit(object sender, DirectEventArgs e) { X.Msg.Alert("Submit", "Submitted").Show(); }Ext.NET v2 Example
<ext:FormPanel ID="FormPanel1" runat="server" Width="200"> <Items> <ext:TextField runat="server" AllowBlank="false" /> </Items> <Buttons> <ext:Button runat="server" Text="Submit" FormBind="true"> <DirectEvents> <Click OnEvent="Submit" /> </DirectEvents> </ext:Button> </Buttons> </ext:FormPanel> </form>
You can listen a FormPanel's ValidityChange event to apply some custom actions.
来源:https://stackoverflow.com/questions/17001045/form-validation-before-direct-click-event-fire