1. #1
    Sencha User
    Join Date
    Mar 2012
    Location
    Germany, Dresden
    Posts
    35
    Answers
    3
    Vote Rating
    1
    mrVVoo is on a distinguished road

      0  

    Default Answered: Prevent form submit?

    Answered: Prevent form submit?


    Hey,

    i want to set up a login screen which should submit while tapping enter or GO and also while tapping on a submit button. The problem is that i don't want to submit this form data to a url.

    i read that i can prevent this submit action but actually i don't know how. i tried "submit" and "before submit" listeners (which return false like written in documentation) but submit is performed. (Either i get an error that no url is specified or (if i specify it) i get an error that result couldn't be parsed as JSON or error 404)

    i only need the data typed in the form and don't wanna perform a submit action. what is the best solution to do that?

  2. There was a bug in 2.0.0 but in 2.0.1 RC this is fixed and can do this to cancel:

    Code:
    new Ext.form.Panel({
        fullscreen : true,
        items      : [
            {
                xtype : 'textfield',
                label : 'Test'
            },
            {
                xtype   : 'button',
                text    : 'Submit',
                handler : function(button) {
                    var form = button.up('formpanel');
    
                    form.submit();
                }
            }
        ],
        listeners : {
            beforesubmit : function() {
                return false;
            }
        }
    });
    In 2.0.0 you can do this:

    Code:
    new Ext.form.Panel({
        fullscreen : true,
        items      : [
            {
                xtype : 'textfield',
                label : 'Test'
            },
            {
                xtype   : 'button',
                text    : 'Submit',
                handler : function(button) {
                    var form = button.up('formpanel');
    
                    form.submit();
                }
            }
        ],
        listeners : {
            order        : 'before',
            beforesubmit : function() {
                return false;
            }
        }
    });

  3. #2
    Sencha - Senior Forum Manager mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    36,649
    Answers
    3454
    Vote Rating
    817
    mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute mitchellsimoens has a reputation beyond repute

      0  

    Default


    There was a bug in 2.0.0 but in 2.0.1 RC this is fixed and can do this to cancel:

    Code:
    new Ext.form.Panel({
        fullscreen : true,
        items      : [
            {
                xtype : 'textfield',
                label : 'Test'
            },
            {
                xtype   : 'button',
                text    : 'Submit',
                handler : function(button) {
                    var form = button.up('formpanel');
    
                    form.submit();
                }
            }
        ],
        listeners : {
            beforesubmit : function() {
                return false;
            }
        }
    });
    In 2.0.0 you can do this:

    Code:
    new Ext.form.Panel({
        fullscreen : true,
        items      : [
            {
                xtype : 'textfield',
                label : 'Test'
            },
            {
                xtype   : 'button',
                text    : 'Submit',
                handler : function(button) {
                    var form = button.up('formpanel');
    
                    form.submit();
                }
            }
        ],
        listeners : {
            order        : 'before',
            beforesubmit : function() {
                return false;
            }
        }
    });
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Forum Manager
    ________________
    Check out my GitHub, lots of nice things for Ext JS 4 and Sencha Touch 2
    https://github.com/mitchellsimoens

    Think my support is good? Get more personalized support via a support subscription. https://www.sencha.com/store/

    Need more help with your app? Hire Sencha Services services@sencha.com

    Want to learn Sencha Touch 2? Check out Sencha Touch in Action that is in print!

    When posting code, please use BBCode's CODE tags.

  4. #3
    Sencha User
    Join Date
    Mar 2012
    Location
    Germany, Dresden
    Posts
    35
    Answers
    3
    Vote Rating
    1
    mrVVoo is on a distinguished road

      0  

    Default


    thanks, i'm already using 2.0.1 RC1.

    i had a bug after refactoring my code. I've added a listener to the field set and not to the ext.form.panel. But with your solution i was able to optimize my code.

  5. #4
    Sencha User
    Join Date
    Oct 2011
    Location
    Pakistan
    Posts
    229
    Answers
    10
    Vote Rating
    1
    umr.ashrf is on a distinguished road

      0  

    Default


    I think the issue is still not fixed as I just tried it.

    I have a form which I want to get submitted to a URL by user pressing the external login button or the enter/go on android.

    And on beforesubmit listener, I do...

    //validate inputs

    // return false;

    On external button, I do..

    getForm().submit({
    url: '/users/login'
    });

    Here's the problem, the submit function is being called even though I am returning false in beforesubmit handler.

  6. #5
    Sencha User
    Join Date
    Mar 2012
    Location
    Germany, Dresden
    Posts
    35
    Answers
    3
    Vote Rating
    1
    mrVVoo is on a distinguished road

      0  

    Default


    well for me it works. i didn't provide an url and that should cause an error which not occurs.
    also no network request starts. which version do you use? ST2.0.1RC?

  7. #6
    Sencha Premium Member
    Join Date
    Nov 2011
    Posts
    89
    Vote Rating
    4
    anand.arvind can only hope to improve

      0  

    Default Does not work in 2.0.1 RC

    Does not work in 2.0.1 RC


    Found this still does not work, the 2.0.0 workaround works even in 2.0.1. Can someone confirm this is really fixed and working in 2.0.1 - I see the submit event fired in doBeforeSubmit code even when I return false (my check for before submit gets called after the core one by which time the ajax request has already been started).

    Also I have three listeners, beforesubmit, submit and exception, if I add order before for this group, then does this have any side effects for submit and exception

    listeners: {
    order : 'before',
    beforesubmit: function(form, results) {
    return this.onBeforeSubmit(form, results);
    },
    submit: function(form, results) {
    return this.onSubmit(form, results);
    },
    exception: function(form, results) {
    return this.onException(form, results);
    }
    }



    Thanks
    Anand