Results 1 to 4 of 4

Thread: Form Submission Without JSON Success Propery

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Sencha Premium Member
    Join Date
    Oct 2009
    Posts
    23
    Answers
    3

    Default Answered: Form Submission Without JSON Success Propery

    Interacting with an existing REST server which does not include the success: property in JSON responses. It uses the HTTP status code to indicate success or failure. Obviously work fine using Ext.Ajax.request's success() and failure() handlers.

    I'd like to get Form.submit() working the same way. Form.submit() requires a success: true|false value pair in the JSON resonse in order to call either the success or failure callbacks. Is there a way for me to globally override the Form.submit() functionality to call the success handler if HTTP status code 200 regardless of there being a success: true value pair in the JSON response so I can take advantage of everything the built-in Form.submit() offers?

  2. Yes, got it working. The following code was placed in ./overrides/form/action/Submit.js of the sencha cmd generated app as such...

    Code:
    Ext.define('Ext.overrides.form.action.Submit',{
      override: 'Ext.form.action.Submit',
      
        onSuccess: function(response) {
            var form = this.form,
                formActive = form && !form.destroying && !form.isDestroyed,
                success = true,
                result = this.processResponse(response);
            
            // This override ignores the result.success being present or
            // not in the JSON reply as we just want to rely on the HTTP status
            // code to determine success or failure
            if (result !== true && (result.errors && formActive)) {
                form.markInvalid(result.errors);
                this.failureType = Ext.form.action.Action.SERVER_INVALID;
                success = false;
            }
            
            if (formActive) {
                form.afterAction(this, success);
            }
        }
    });
    Note that I had to do a
    Code:
    sencha app refresh
    before the override was recognized? Not exactly sure why.

    After the override was picked up, the form submit is considered a success even without a {success: true} in the JSON reply as long as the HTTP status code is success.

    It sure would be nice to have a config option on the FormPanel which would tell the Submit action that {success: true} is not a requirement in the JSON reply.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •