0
votes

I have a problem here, here is the code.

function addProduct () {
    var prod_form = Ext.getCmp('productForm');

    if(!prod_form.getForm().isValid()) {
        Ext.Msg.show({
            title:'Warning',
            msg: 'Please verify the field(s) marked in <font color="red">red</font>',
            icon: Ext.Msg.WARNING,
            buttons: Ext.Msg.OK  
        })
        return;
    }

    prod_form.getForm().submit({
        url: 'save',
        success: function(prod_form,action) {
            console.log('SUCCESS');
            Ext.Msg.show({
                title: 'Adding the Product Successful',
                msg: 'Data has been saved!'
            })
        },
        failure : function(prod_form,action) {
            console.log('FAILURE');
            Ext.Msg.show({
                title: 'Error',
                msg: 'Failure in adding the Product',
                buttons: Ext.Msg.OK
            })
        }
    })
}

i have a function add product in extjs and it handles the button Add Product whenever it is clicked. then it will load the modal which has the form inside. it do work but the problem is in the success and failure function.

It returns the failure function, but it does write the data in the database.

Why is this?

thanks!!

2

2 Answers

1
votes

Make sure your back end returns success: true in the response payload otherwise all calls to form.submit() will "fail" even though it may have worked.

If you can't change the back end to return the success variable, you could use errorReader property of the form.

0
votes

So for symfony 2 users, what you need to do is to create a json response,

success: true