TextField and Button Validation

  1. #1

    TextField and Button Validation

    Hello,

    I've got an ExtJS TextField and a Button, the TextField is setup not to allow an empty submit however, when I click the login button it does not show the validation ... unless I click inside the TextField and lose focus.

    Here is what I've got:

    
    <ExtJS:TextField ID="txtUsername" runat="server" AllowEmpty="False" />
    <ExtJS:Button ID="btnLogin" runat="server" Text="Login" CausesValidation="True" &#111;nclick="btnLogin_Click" />
    Cheers,
    Timothy
  2. #2

    RE: TextField and Button Validation

    Hi Timothy,

    We're working on a sample for you, but ran into a bug. We're fixing right now. I should have a working sample for you shortly.

    I apologize for the delay.
    Geoffrey McGill
    Founder
  3. #3

    RE: TextField and Button Validation

    No problem, thanks for the response :)

    The bug wouldn't be what I'm encountering would it?

    Cheers,
    Timothy
  4. #4

    RE: TextField and Button Validation

    Hi Timothy,

    Ok we fixed the bug I was having problems with and I made a simple sample demonstrating how to trigger the validation and stop the postback from occurring.

    <%@ Page Language="C#" %>
    
    <%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <script runat="server">
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            this.Label1.Text = this.txtUsername.Text;
        }
    </script>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Coolite Toolkit - Simple Field Validation</title>
    </head>
    <body>
        <form id="Form2" runat="server">
        <p><a href="Validation.aspx">Reload</a></p>
            <ext:ScriptManager runat="server" StateProvider="PostBack" Theme="Gray" />
            <ext:TextField ID="txtUsername" runat="server" AllowBlank="false" />
            <ext:Button ID="btnLogin" runat="server" Text="Login" CausesValidation="True" &#111;nclick="btnLogin_Click">
                <Listeners>
                    <Click Handler="
                        txtUsername.validate(); 
                        if (!txtUsername.isValid()) { 
                            txtUsername.focus(); // if Username invalid, focus the field.
                            return false;
                        }"
                        />
                </Listeners>
            </ext:Button>
            <asp:Label ID="Label1" runat="server" />
        </form>
    </body>
    </html>
    Are you building from SVN source? If you SVN Update, then rebuild, the above sample should work for you.

    The key is calling .validate() on the TextField and then return "false" from the <Click> Handler, which will prevent the postback. Return "true" or don't return anything and the postback will happen as expected.

    The example above demonstrates a manual (and granular) way of triggering the validation, although we've got a bunch of form work which should be included in the project shortly. The new work should handle all of this validation automatically. I'll keep this thread updated with our progress.

    I'm also putting together a more complex sample to demonstrate multiple fields and field types.

    Please let me know if you have any questions or comments and I'll do my best to help out.
    Geoffrey McGill
    Founder
  5. #5

    RE: TextField and Button Validation

    You have any idea when the automatic validation will take place? Would really like to have that cleared up on a project I'm working with :)

    Cheers,
    Timothy
  6. #6

    RE: TextField and Button Validation

    Hi Timothy

    Thank you for your question. As already mentioned Geoffrey, we are
    working now on the FormPanel. The FormPanel will contain functionality
    automatically check all fields. This will greatly simplify the code for
    developers. Unfortunately, I can not say release date (or the
    appearance of beta versions in svn). But we will periodically update
    this topic that you were aware of progress. If automatically validation is necessary for you now please let me know and we will try to find a solution for you

    Vladimir
  7. #7

    RE: TextField and Button Validation

    Thanks for the response again Vladsch!

    Would be nice to have, but I can deal with the <asp:RequiredFieldValidation /> controls for the time being.

    Cheers,
    Timothy
  8. #8

    RE: TextField and Button Validation

    Hello,

    Just wondering what the status of the automatic validation is at?

    Cheers,
    Timothy

Similar Threads

  1. [CLOSED] DirectMethod only when textfield validation
    By CarWise in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jan 11, 2011, 3:05 PM
  2. [CLOSED] Validation Empty TextField
    By pdcase in forum 1.x Legacy Premium Help
    Replies: 1
    Last Post: Jul 16, 2010, 9:11 PM
  3. Validation Empty TextField
    By Krisller in forum 1.x Help
    Replies: 0
    Last Post: Jun 16, 2010, 2:20 PM
  4. MaxLength validation in TextField & NumericField
    By madhugumma in forum 1.x Help
    Replies: 0
    Last Post: Aug 06, 2009, 4:46 AM
  5. Replies: 4
    Last Post: Jul 05, 2008, 2:14 AM

Posting Permissions