Hybrid View

  1. #1
    Sencha User
    Join Date
    Oct 2012
    Posts
    28
    Vote Rating
    0
    desp is on a distinguished road

      0  

    Default Unanswered: Checkbox value "on" on form.loadRecord() and ajaxSubmit config

    Unanswered: Checkbox value "on" on form.loadRecord() and ajaxSubmit config


    Hi,
    Is it bug or just me? I am loading form data as JSON from server, and values for checkbox'es are string "on", but when form.loadRecord(...) is called it does not make it checked. It works when value is boolean true. The "on" value is get directly from POST. I was looking how to set form to send it's data as JSON and found jsonSubmit config for form panel class, but it is not working. I submit form int this way:

    HTML Code:
              if (form.isValid()) {
                    form.submit({
                        clientValidation: true,
                        url: '/backend/ctrl/savePresetData/' + node.data.id,
                        headers: {
                            'Accept': 'application/json'
                        },
    
                        success: function(form, action) {
                            Ext.Msg.alert('Success', 'Succesfully saved!');
                        },
                        failure: function(form, action) {
                            switch (action.failureType) {
                                case Ext.form.action.Action.CLIENT_INVALID:
                                    Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
                                    break;
                                case Ext.form.action.Action.CONNECT_FAILURE:
                                    Ext.Msg.alert('Failure', 'Ajax communication failed');
                                    break;
                                case Ext.form.action.Action.SERVER_INVALID:
                                    Ext.Msg.alert('Failure', action.result.msg);
                            }
                        }
                    });
    It realy has jsonSubmit config:
    HTML Code:
    Ext.define('AC.view.myForm', {
        extend: 'Ext.form.Panel',
        alias: 'widget.mypanel',
    ....
        width: '100%',
        frame: true,
        border: 0,
        jsonSubmit: true,  // <--- is it good?

  2. #2
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    1. What do your checkboxes' code look like? What are the respective values in the record? When you load record to a form, its checkbox will be checked if the value in record is one of the following:
    - true.
    - 'true'.
    - '1'.
    - 1.
    - value of checkbox inputValue or 'on' (if there is no inputValue).
    2. When you submit the form, a checkbox will be sent with inputValue (if it is checked) or uncheckedValue (if it is unchecked).

  3. #3
    Sencha User
    Join Date
    Oct 2012
    Posts
    28
    Vote Rating
    0
    desp is on a distinguished road

      0  

    Default


    Thanks, vietits, inputValue and uncheckedValue worked! :-) So many config vars to spot what you need hehe.

    On another problem I still can not make my forms to send POST values as JSON. According to Ext.form.Panel documentation, it accepts Ext.form.Basic configs also but it seems does not work when calling .submit() method explicitly

  4. #4
    Sencha User
    Join Date
    Oct 2012
    Posts
    28
    Vote Rating
    0
    desp is on a distinguished road

      0  

    Default


    I see if autoSync in store is set to true it posts data to server as JSON. How to achieve this when using Ex.Ajax.request() or form.submit()?

  5. #5
    Sencha User
    Join Date
    Oct 2012
    Posts
    28
    Vote Rating
    0
    desp is on a distinguished road

      0  

    Default


    I find out myself that jsonData instead of params in Ext.Ajax.request() does exactly what I needed :-)

  6. #6
    Sencha - Community Support Team
    Join Date
    Jan 2012
    Posts
    1,376
    Answers
    346
    Vote Rating
    113
    vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all vietits is a name known to all

      0  

    Default


    To submit form data in json format, you should use Ext.Ajax.request():
    Code:
      if (form.isValid()) {
    //        form.submit({
    //            clientValidation: true,
            Ext.Ajax.request({
        jsonData: form.getValues(),
                url: '/backend/ctrl/savePresetData/' + node.data.id,
                headers: {
                    'Accept': 'application/json'
                },
                success: function(form, action) {
                    Ext.Msg.alert('Success', 'Succesfully saved!');
                },
                failure: function(form, action) {
                    switch (action.failureType) {
                        case Ext.form.action.Action.CLIENT_INVALID:
                            Ext.Msg.alert('Failure', 'Form fields may not be submitted with invalid values');
                            break;
                        case Ext.form.action.Action.CONNECT_FAILURE:
                            Ext.Msg.alert('Failure', 'Ajax communication failed');
                            break;
                        case Ext.form.action.Action.SERVER_INVALID:
                            Ext.Msg.alert('Failure', action.result.msg);
                    }
                }
            });

Thread Participants: 1