Ext


Go Back   Ext JS Forums > Ext JS Community Forums (2.0) > Ext 2.x: Help

Reply
 
Thread Tools
  #1  
Old 09-04-2008, 04:49 PM
cornflakes cornflakes is offline
Ext User
 
Join Date: Jun 2008
Posts: 20
cornflakes is on a distinguished road
Default Login Form: Disable 'submit' until username has been input

If this has been discussed elsewhere, please let me know and I'll move/remove this post.

Currently, I have a login form and would like to disable the 'submit' button until the user has input a username (and password) in the text fields. Any ideas on how I can do this?

Thanks in advance.
Reply With Quote
  #2  
Old 09-04-2008, 05:22 PM
devnull devnull is offline
Ext JS - Support Team
 
Join Date: Jul 2007
Posts: 3,128
devnull is on a distinguished road
Default

'monitorValid' in FormPanel and 'formBind' in Button are designed to do just this when combined with field validation.
Reply With Quote
  #3  
Old 09-05-2008, 03:50 PM
cornflakes cornflakes is offline
Ext User
 
Join Date: Jun 2008
Posts: 20
cornflakes is on a distinguished road
Default

Thanks, devnull but I don't see formBind in the API docs for Button. Where can I find this?
Reply With Quote
  #4  
Old 09-05-2008, 04:02 PM
devnull devnull is offline
Ext JS - Support Team
 
Join Date: Jul 2007
Posts: 3,128
devnull is on a distinguished road
Default

It apparently is not listed in the Button API docs, but is talked about in the monitorValid docs for formPanel.
You'll probably find alot of examples here of you search for formBind.
Reply With Quote
  #5  
Old 09-05-2008, 04:22 PM
cornflakes cornflakes is offline
Ext User
 
Join Date: Jun 2008
Posts: 20
cornflakes is on a distinguished road
Default

Ok, thanks.

I have set both monitorValid (in FormPanel) and formBind (in the submit Button) and the button is still active. Any ideas?

The code is:

Ext.onReady( function()
    {
        var login = new Ext.form.FormPanel(
        {
            labelWidth :90,
            url :'<%=request.getContextPath()%>/j_security_check',
            method :'POST',
            id :'_loginForm',
            standardSubmit :true,
            frame :true,
            title :'Login',
            bodyStyle :'padding:5px 5px 0',
            iconCls :'user-suit',
            width :350,
            monitorValid:true, <------------------- monitorValid
            keys:
            [
                {
                    key: Ext.EventObject.ENTER,
                    fn: function()
                    {
                        var sb = Ext.getCmp('my-status');
                        sb.showBusy();
                        document.getElementsByTagName("form")[1].action = "<%=request.getContextPath()%>/j_security_check";
                        document.getElementsByTagName("form")[1].submit();
                    }
                }
            ],
            defaults :
            {
                <%-- 
                    enter defaults here
                    width :230 
                --%>
            },
            defaultType :'textfield',
            items :
            [
                {
                    fieldLabel :'Username',
                    name :'j_username',
                    id :'j_username',
                    allowBlank :false
                },
                {
                    fieldLabel :'Password',
                    name :'j_password',
                    id :'j_password',
                    allowblank :false,
                    inputType :'password'
                },{
                    fieldLabel: 'Remember Me',
                    boxLabel : 'rememberMe',
                    name : 'rememberMe',
                    inputType: 'checkbox'
                },{
                    xtype :'panel',
                    buttonAlign :'right',
                    width :340,
                    buttons :
                    [
                        {
                            text :'Signup',
                            type :'signup',
                            minWidth: 75,
                            handler :function()
                            {
                                document.getElementsByTagName("form")[1].action = "<%=request.getContextPath()%>/register.html";
                                document.getElementsByTagName("form")[1].submit();
                            }
                        },
                        {
                            text :'Login',
                            formBind:true, <------------------- formBind
                            type :'submit',
                            minWidth: 75,
                            handler :function()
                            {
                                var sb = Ext.getCmp('my-status');
                                sb.showBusy();
                                document.getElementsByTagName("form")[1].action = "<%=request.getContextPath()%>/j_security_check";
                                document.getElementsByTagName("form")[1].submit();
                            }                    
                        }
                    ]
                }
            ],
           bbar: new Ext.StatusBar(
            {
                id: 'my-status',
                text: 'Ready',
                iconCls: 'default-icon',
                busyText: 'Validating...'
        <%
            if (!(request.getParameter("login_error") == null))
            {
                String errorMsg = request.getSession().getAttribute("SPRING_SECURITY_LAST_EXCEPTION").toString();
                errorMsg = errorMsg.substring(errorMsg.indexOf(':') + 1, errorMsg.length());
        %>
                ,items:
                [
                    '<div style=\'color: red; vertical-align: top; padding-right: 5px;\'><%=errorMsg%><br/></div>'
                ]
        <%    } %>
            })
        });
        login.render(document.getElementById('_login'));
    });
Reply With Quote
  #6  
Old 09-06-2008, 08:32 PM
cornflakes cornflakes is offline
Ext User
 
Join Date: Jun 2008
Posts: 20
cornflakes is on a distinguished road
Default

I think I know the problem. The buttons (with formBind:true) cannot be declared inside the xtype:'panel'. Instead, buttons should be declared directly in the FormPanel. This changes the layout a little, but the button is now disabled as it should be (until the user enters text in the text fields where allowBlank is false).

So, the steps taken to have the button disabled are:

1. set monitorValid:true in FormPanel
2. declare buttons in FormPanel
3. set formBind:true in the button
4. set allowBlank:false in the fields used to determine the status of the button.
Reply With Quote
  #7  
Old 09-06-2008, 09:31 PM
cornflakes cornflakes is offline
Ext User
 
Join Date: Jun 2008
Posts: 20
cornflakes is on a distinguished road
Default

For anyone who wants it, the code to get this to work is (ignore the scriplets or comment them out):

Ext.onReady( function()
    {
        Ext.QuickTips.init();
        
        var login = new Ext.FormPanel(
        {
            labelWidth :90,
            url :'<%=request.getContextPath()%>/j_security_check',
            method :'POST',
            id :'_loginForm',
            standardSubmit :true,
            frame :true,
            title :'Login',
            bodyStyle :'padding:5px 5px 0',
            iconCls :'user-suit',
            width :350,
            monitorValid:true,
            keys:
            [
                {
                    key: Ext.EventObject.ENTER,
                    fn: function()
                    {
                        var sb = Ext.getCmp('my-status');
                        sb.showBusy();
                        document.getElementsByTagName("form")[1].action = "<%=request.getContextPath()%>/j_security_check";
                        document.getElementsByTagName("form")[1].submit();
                    }
                }
            ],
            defaults :
            {
                <%-- 
                    enter defaults here
                    width :230 
                --%>
            },
            defaultType :'textfield',
            items :
            [
                {
                    fieldLabel :'Username',
                    name :'j_username',
                    id :'j_username',
                    allowBlank :false
                },
                {
                    fieldLabel :'Password',
                    name :'j_password',
                    id :'j_password',
                    allowBlank :false,
                    inputType :'password'
                },{
                    fieldLabel: 'Remember Me',
                    boxLabel : 'rememberMe',
                    name : 'rememberMe',
                    inputType: 'checkbox'
                }
                    
            ],
            
            buttons :
                    [
                        {
                            text :'Register',
                            type :'register',
                            minWidth: 75,
                            handler :function()
                            {
                                document.getElementsByTagName("form")[1].action = "<%=request.getContextPath()%>/register.html";
                                document.getElementsByTagName("form")[1].submit();
                            }
                        },
                        {
                            text :'Login',
                            formBind:true,
                            type :'submit',
                            minWidth: 75,
                            handler :function()
                            {
                                var sb = Ext.getCmp('my-status');
                                sb.showBusy();
                                document.getElementsByTagName("form")[1].action = "<%=request.getContextPath()%>/j_security_check";
                                document.getElementsByTagName("form")[1].submit();
                            }                    
                        }
                    ],
                    
           bbar: new Ext.StatusBar(
            {
                id: 'my-status',
                text: 'Ready',
                iconCls: 'default-icon',
                busyText: 'Validating...'
        <%
            if (!(request.getParameter("login_error") == null))
            {
                String errorMsg = request.getSession().getAttribute("SPRING_SECURITY_LAST_EXCEPTION").toString();
                errorMsg = errorMsg.substring(errorMsg.indexOf(':') + 1, errorMsg.length());
        %>
                ,items:
                [
                    '<div style=\'color: red; vertical-align: top; padding-right: 5px;\'><%=errorMsg%><br/></div>'
                ]
        <%    } %>
            })
        });
        login.render(document.getElementById('_login'));
    });
Any ideas on how I can move that status indicator to the bottom of the form? I can do this if I use the approach above (see code example earlier in this post), but then I cannot disable the button.
Reply With Quote
  #8  
Old 09-07-2008, 05:14 AM
Animal's Avatar
Animal Animal is offline
Ext JS - Community Support Team
 
Join Date: Mar 2007
Location: East Midlands, UK
Posts: 23,352
Animal will become famous soon enough
Default

The correct way is to set monitorValid: true, and subscribe to http://extjs.com/deploy/dev/docs/?cl...ientvalidation
__________________
ExtJs forum volunteer. No official connection to the Ext Company. I do not speak for them.
ExtJs consultancy offered. £ 50/hour. Evenings+weekends. the_bagbournes@btinternet.com

Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
See Saki's samples: http://examples.extjs.eu/
Build your own Ext: http://extjs.com/products/extjs/build/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
Reply With Quote
  #9  
Old 09-07-2008, 07:27 PM
cornflakes cornflakes is offline
Ext User
 
Join Date: Jun 2008
Posts: 20
cornflakes is on a distinguished road
Default

Thanks Animal.

The issue I am having is if I use the first code snippet, the button is never disabled. When using the second code snippet, the button is properly disabled (and enabled after correct values have been input into the fields), but the form looks a little odd in that the status bar is above the buttons. Instead, I'm trying to put that status bar below the button.

To summarize, how can I use code snippet 2 but put the status bar to the bottom of the panel (as in code snippet 1)?
Reply With Quote
Reply

Thread Tools

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

All times are GMT -5. The time now is 09:08 PM.

© 2006-2009 Ext, LLC
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.