Sencha Documentation

Provides Ext.direct support for submitting form data.

This example illustrates usage of Ext.Direct to submit a form through Ext.Direct.

var myFormPanel = new Ext.form.FormPanel({
    // configs for FormPanel
    title: 'Basic Information',
    renderTo: document.body,
    width: 300, height: 160,
    padding: 10,
    buttons:[{
        text: 'Submit',
        handler: function(){
            myFormPanel.getForm().submit({
                params: {
                    foo: 'bar',
                    uid: 34
                }
            });
        }
    }],

    // configs apply to child items
    defaults: {anchor: '100%'},
    defaultType: 'textfield',
    items: [{
        fieldLabel: 'Name',
        name: 'name'
    },{
        fieldLabel: 'Email',
        name: 'email'
    },{
        fieldLabel: 'Company',
        name: 'company'
    }],

    // configs for BasicForm
    api: {
        // The server-side method to call for load() requests
        load: Profile.getBasicInfo,
        // The server-side must mark the submit handler as a 'formHandler'
        submit: Profile.updateBasicInfo
    },
    // specify the order for the passed params
    paramOrder: ['uid', 'foo']
});
The data packet sent to the server will resemble something like:
{
    "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":"6",
    "result":{
        "success":true,
        "id":{
            "extAction":"Profile","extMethod":"updateBasicInfo",
            "extType":"rpc","extTID":"6","extUpload":"false",
            "name":"Aaron Conran","email":"[email protected]","company":"Ext JS, LLC"
        }
    }
}
The form will process a data packet returned by the server that is similar to the following:
// sample success packet (batched requests)
[
    {
        "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":3,
        "result":{
            "success":true
        }
    }
]

// sample failure packet (one request)
{
        "action":"Profile","method":"updateBasicInfo","type":"rpc","tid":"6",
        "result":{
            "errors":{
                "email":"already taken"
            },
            "success":false,
            "foo":"bar"
        }
}
Also see the discussion in Ext.form.DirectLoadAction.

Config Options

 
Determines whether a Form's fields are validated in a final call to isValid prior to submission. Pass false in the Fo...
Determines whether a Form's fields are validated in a final call to isValid prior to submission. Pass false in the Form's submit options to prevent this. Defaults to true.
 
failure : Function
The function to call when a failure packet was received, or when an error ocurred in the Ajax communication. The func...
The function to call when a failure packet was received, or when an error ocurred in the Ajax communication. The function is passed the following parameters:
  • form : Ext.form.Basic
    The form that requested the action
  • action : Ext.form.action.Action
    The Action class. If an Ajax error ocurred, the failure type will be in failureType. The result property of this object may be examined to perform custom postprocessing.
 
form : Ext.form.Basic
The BasicForm instance that is invoking this Action. Required.
The BasicForm instance that is invoking this Action. Required.
 
headers : Object

Extra headers to be sent in the AJAX request for submit and load actions. See Ext.data.Connection.headers.

Extra headers to be sent in the AJAX request for submit and load actions. See Ext.data.Connection.headers.

 
method : String
The HTTP method to use to access the requested URL. Defaults to the BasicForm's method, or 'POST' if not specified.
The HTTP method to use to access the requested URL. Defaults to the BasicForm's method, or 'POST' if not specified.
 
params : Object/String
Extra parameter values to pass. These are added to the Form's Ext.form.Basic.baseParams and passed to the specified U...

Extra parameter values to pass. These are added to the Form's Ext.form.Basic.baseParams and passed to the specified URL along with the Form's input fields.

Parameters are encoded as standard HTTP parameters using Ext.urlEncode.

 
reset : Boolean
When set to true, causes the Form to be reset on Action success. If specified, this happens before the success callba...
When set to true, causes the Form to be reset on Action success. If specified, this happens before the success callback is called and before the Form's actioncomplete event fires.
 
scope : Object
The scope in which to call the configured success and failure callback functions (the this reference for the callback...
The scope in which to call the configured success and failure callback functions (the this reference for the callback functions).
 
submitEmptyText : Boolean
If set to true, the emptyText value will be sent with the form when it is submitted. Defaults to true.
If set to true, the emptyText value will be sent with the form when it is submitted. Defaults to true.
 
success : Function
The function to call when a valid success return packet is received. The function is passed the following parameters:...
The function to call when a valid success return packet is received. The function is passed the following parameters:
  • form : Ext.form.Basic
    The form that requested the action
  • action : Ext.form.action.Action
    The Action class. The result property of this object may be examined to perform custom postprocessing.
 
timeout : Number
The number of seconds to wait for a server response before failing with the failureType as Ext.form.action.Action.CON...
The number of seconds to wait for a server response before failing with the failureType as Ext.form.action.Action.CONNECT_FAILURE. If not specified, defaults to the configured timeout of the form.
 
url : String
The URL that the Action is to invoke. Will default to the url configured on the form.
The URL that the Action is to invoke. Will default to the url configured on the form.
 
waitMsg : String
The message to be displayed by a call to Ext.MessageBox.wait during the time the action is being processed.
The message to be displayed by a call to Ext.MessageBox.wait during the time the action is being processed.
 
waitTitle : String
The title to be displayed by a call to Ext.MessageBox.wait during the time the action is being processed.
The title to be displayed by a call to Ext.MessageBox.wait during the time the action is being processed.

Properties

 
Failure type returned when client side validation of the Form fails thus aborting a submit action. Client side valida...
Failure type returned when client side validation of the Form fails thus aborting a submit action. Client side validation is performed unless Ext.form.action.Submit.clientValidation is explicitly set to false.
 
Failure type returned when a communication error happens when attempting to send a request to the remote server. The ...
Failure type returned when a communication error happens when attempting to send a request to the remote server. The response may be examined to provide further information.
 
LOAD_FAILURE : String
Failure type returned when the response's success property is set to false, or no field values are returned in the re...
Failure type returned when the response's success property is set to false, or no field values are returned in the response's data property.
 
Failure type returned when server side processing fails and the result's success property is set to false. In the cas...

Failure type returned when server side processing fails and the result's success property is set to false.

In the case of a form submission, field-specific error messages may be returned in the result's errors property.

 
failureType : String
The type of failure detected will be one of these: Ext.form.action.Action.CLIENT_INVALID, Ext.form.action.Action.SERV...
The type of failure detected will be one of these: Ext.form.action.Action.CLIENT_INVALID, Ext.form.action.Action.SERVER_INVALID, Ext.form.action.Action.CONNECT_FAILURE, or Ext.form.action.Action.LOAD_FAILURE. Usage:
var fp = new Ext.form.FormPanel({
...
buttons: [{
    text: 'Save',
    formBind: true,
    handler: function(){
        if(fp.getForm().isValid()){
            fp.getForm().submit({
                url: 'form-submit.php',
                waitMsg: 'Submitting your data...',
                success: function(form, action){
                    // server responded with success = true
                    var result = action.result;
                },
                failure: function(form, action){
                    if (action.failureType === Ext.form.action.Action.Ext.form.action.Action.CONNECT_FAILURE) {
                        Ext.Msg.alert('Error',
                            'Status:'+action.response.status+': '+
                            action.response.statusText);
                    }
                    if (action.failureType === Ext.form.action.Action.Ext.form.action.Action.SERVER_INVALID){
                        // server responded with success = false
                        Ext.Msg.alert('Invalid', action.result.errormsg);
                    }
                }
            });
        }
    }
},{
    text: 'Reset',
    handler: function(){
        fp.getForm().reset();
    }
}]
 
response : Object
The raw XMLHttpRequest object used to perform the action.
The raw XMLHttpRequest object used to perform the action.
 
result : Object
The decoded response object containing a boolean success property and other, action-specific properties.
The decoded response object containing a boolean success property and other, action-specific properties.
 
run : Object
Invokes this action using the current configuration.
Invokes this action using the current configuration.
 
self : Class
Get the reference to the current class from which this object was instantiated. Unlike Ext.Base.statics, `this.self` ...

Get the reference to the current class from which this object was instantiated. Unlike Ext.Base.statics, this.self is scope-dependent and it's meant to be used for dynamic inheritance. See Ext.Base.statics for a detailed comparison

Ext.define('My.Cat', {
    statics: {
        speciciesName: 'Cat' // My.Cat.speciciesName = 'Cat'
    },

    constructor: function() {
        alert(this.self.speciciesName); / dependent on 'this'

        return this;
    },

    clone: function() {
        return new this.self();
    }
});


Ext.define('My.SnowLeopard', {
    extend: 'My.Cat',
    statics: {
        speciciesName: 'Snow Leopard' // My.SnowLeopard.speciciesName = 'Snow Leopard'
    }
});

var kitty = new My.Cat();           // alerts 'Cat'
var katty = new My.SnowLeopard();   // alerts 'Snow Leopard'

var cutie = katty.clone();
alert(Ext.getClassName(cutie));     // alerts 'My.SnowLeopard'
 
type : String
The type of action this Action instance performs. Currently only "submit" and "load" are supported.
The type of action this Action instance performs. Currently only "submit" and "load" are supported.

Methods

 
callOverridden( Array/Arguments args ) : Mixed
Call the original method that was previously overridden with Ext.Base.override Ext.define('My.Cat', { co...

Call the original method that was previously overridden with Ext.Base.override

Ext.define('My.Cat', {
    constructor: function() {
        alert("I'm a cat!");

        return this;
    }
});

My.Cat.override({
    constructor: function() {
        alert("I'm going to be a cat!");

        var instance = this.callOverridden();

        alert("Meeeeoooowwww");

        return instance;
    }
});

var kitty = new My.Cat(); // alerts "I'm going to be a cat!"
                          // alerts "I'm a cat!"
                          // alerts "Meeeeoooowwww"

Parameters

  • args : Array/Arguments

    The arguments, either an array or the arguments object

Returns

  • Mixed   Returns the result after calling the overridden method
 
callParent( Array/Arguments args ) : Mixed
Call the overridden superclass' method. For example: Ext.define('My.own.A', { constructor: function(test...

Call the overridden superclass' method. For example:

Ext.define('My.own.A', {
    constructor: function(test) {
        alert(test);
    }
});

Ext.define('My.own.B', {
    constructor: function(test) {
        alert(test);

        this.callParent([test + 1]);
    }
});

var a = new My.own.A(1); // alerts '1'
var b = new My.own.B(1); // alerts '1', then alerts '2'

Parameters

  • args : Array/Arguments

    The arguments, either an array or the arguments object from the current method, for example: this.callParent(arguments)

Returns

  • Mixed   Returns the result from the superclass' method
 
constructor : Object
Default constructor, simply returns `this`
Default constructor, simply returns `this`
 
initConfig( Object config ) : Object
Initialize configuration for this class. a typical example: Ext.define('My.awesome.Class', { // The defa...
Initialize configuration for this class. a typical example: Ext.define('My.awesome.Class', { // The default config config: { name: 'Awesome', isAwesome: true }, constructor: function(config) { this.initConfig(config); return this; } }); var awesome = new My.awesome.Class({ name: 'Super Awesome' }); alert(awesome.getName()); // 'Super Awesome'

Parameters

  • config : Object

Returns

  • Object   mixins The mixin prototypes as key - value pairs
 
statics : Class
Get the reference to the class from which this object was instantiated. Note that unlike Ext.Base.self, `this.statics...

Get the reference to the class from which this object was instantiated. Note that unlike Ext.Base.self, this.statics() is scope-independent and it always returns the class from which it was called, regardless of what this points to during runtime

Ext.define('My.Cat', {
    statics: {
        speciciesName: 'Cat' // My.Cat.speciciesName = 'Cat'
    },

    constructor: function() {
        alert(this.statics().speciciesName); // always equals to 'Cat' no matter what 'this' refers to
                                             // equivalent to: My.Cat.speciciesName

        alert(this.self.speciciesName);      // dependent on 'this'

        return this;
    },

    clone: function() {
        var cloned = new this.self;                      // dependent on 'this'

        cloned.groupName = this.statics().speciciesName; // equivalent to: My.Cat.speciciesName

        return cloned;
    }
});


Ext.define('My.SnowLeopard', {
    statics: {
        speciciesName: 'Snow Leopard' // My.SnowLeopard.speciciesName = 'Snow Leopard'
    },

    constructor: function() {
        this.callParent();
    }
});

var kitty = new My.Cat();         // alerts 'Cat', then alerts 'Cat'

var katty = new My.SnowLeopard(); // alerts 'Cat', then alerts 'Snow Leopard'

var cutie = kitty.clone();
alert(Ext.getClassName(cutie));   // alerts 'My.SnowLeopard'
alert(cutie.groupName);           // alerts 'Cat'