form validation before direct click event fire

元气小坏坏 提交于 2020-01-02 16:15:23

问题


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.

  1. 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>
    

  2. 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>
    

  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!