1. #1
    Sencha User
    Join Date
    Oct 2011
    Location
    São Paulo - SP
    Posts
    22
    Vote Rating
    0
    maps_tecnologia is on a distinguished road

      0  

    Default Unanswered: Submit form - post whole record.

    I have a combobox and a datefield on my form. The combo box is backed up by a store and only show one field of it, like:
    A record: {name: bla, id:7. class: ble}
    Combobox shows: bla

    I want to submit my form POSTing my fields as JSON data, but don't want to post like: {name:bla, date:01/01/1900}.
    I want my combobox to submit the ENTIRE record, as such: {{name: bla, id:7. class: ble}date:01/01/1900}

    I am using a hiddenField and manually setting him like: hiddenField.setValue(record.get('a')........);

    Is there a better way to do this, maybe a "Extjs-way"?

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    38,582
    Vote Rating
    1136
    Answers
    3709
    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

    You can pass in a params object in the submit method
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Software Engineer
    ________________
    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.

  3. #3
    Sencha User
    Join Date
    Oct 2011
    Location
    São Paulo - SP
    Posts
    22
    Vote Rating
    0
    maps_tecnologia is on a distinguished road

      0  

    Default

    But how can I do something like:

    params: form.getField("combobox").GETMODELOBJECT ?

  4. #4
    Sencha - Services Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,965
    Vote Rating
    12
    Answers
    10
    hendricd will become famous soon enough hendricd will become famous soon enough

      0  

    Default

    Quote Originally Posted by maps_tecnologia View Post
    But how can I do something like:

    params: form.getField("combobox").GETMODELOBJECT ?
    Try:
    Code:
        Ext.pluck(form.getField("combobox").lastSelection || [], 'data')
    This will return a raw Array of selected Record objects (remember Combo support multiSelect).
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  5. #5
    Sencha User
    Join Date
    Oct 2011
    Location
    São Paulo - SP
    Posts
    22
    Vote Rating
    0
    maps_tecnologia is on a distinguished road

      0  

    Default

    Code:
     Ext.pluck(form.findField("combobox").lastSelection || [], 'data')
    It works =DJust so I can get this clearer, what does the
    Code:
    || [], 'data')
    do?

  6. #6
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    38,582
    Vote Rating
    1136
    Answers
    3709
    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

    It tries to get the lastSelection from the combobox but if that is falsey then it will use a blank array '[]'
    Mitchell Simoens @SenchaMitch
    Sencha Inc, Senior Software Engineer
    ________________
    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.

  7. #7
    Sencha User
    Join Date
    Oct 2011
    Location
    São Paulo - SP
    Posts
    22
    Vote Rating
    0
    maps_tecnologia is on a distinguished road

      0  

    Default

    Btw, I tried submiting my record but I got this:
    Code:
    request payload:
    param_bla=%5Bobject%20Object%5D&param_date=19-01-2012
    Code:
    var record = Ext.pluck(form.findField("ComboBox").lastSelection || [], 'data');
    
    Ext.Ajax.request({
          url:'rest/a/getBla',
          method: 'POST',
          headers: {'Content-Type':'application/json; charset=utf-8'},
          params: {
                	'param_bla': record,
                	'param_date': date
         }
    });

  8. #8
    Sencha - Services Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,965
    Vote Rating
    12
    Answers
    10
    hendricd will become famous soon enough hendricd will become famous soon enough

      0  

    Default

    @maps_tecnologia--

    The sample I provided returns an Array of selected records (as ComboBox may be configured to support multiple selections).

    If you are only allowing a SINGLE selection, then just use the first record:

    Code:
    var record = Ext.pluck(form.findField("ComboBox").lastSelection || [], 'data')[0];
    if(record) {
       Ext.Ajax.request({ 
           url        :'rest/a/getBla',       
           method: 'POST', 
           jsonData: Ext.apply( record,  {'param_date': date })   //mix in the date
       });
    }
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


  9. #9
    Sencha User
    Join Date
    Oct 2011
    Location
    São Paulo - SP
    Posts
    22
    Vote Rating
    0
    maps_tecnologia is on a distinguished road

      0  

    Default

    Whoa, thats really nice, thanks!

    Just one more thing (sorry for being so demanding), but my date must be somehow separated from the other data.

    I am trying to send a Java object AND a Date field, so it should be like:
    Code:
    {{class:person, name:maps, age: 18}, date: 01-01-1990}
    I am trying, but with no success, things like:
    Code:
    jsonData:
        record,
        date
    ....

  10. #10
    Sencha - Services Team hendricd's Avatar
    Join Date
    Aug 2007
    Location
    Long Island, NY USA
    Posts
    5,965
    Vote Rating
    12
    Answers
    10
    hendricd will become famous soon enough hendricd will become famous soon enough

      0  

    Default

    So, that would be :

    jsonData : { record : record, date : yourDate }
    "be dom-ready..."
    Doug Hendricks

    Maintaining ux: ManagedIFrame, MIF2 (FAQ, Wiki), ux.Media/Flash, AudioEvents, ux.Chart[Fusion,OFC,amChart], ext-basex.js/$JIT, Documentation Site.


    Got Sencha licensing questions? Find out more here.


Thread Participants: 2