Results 1 to 3 of 3

Thread: Correct Way To Bind a Record to a Form?

  1. #1
    Sencha Touch Premium User
    Join Date
    Oct 2010
    Location
    Portland, Maine USA
    Posts
    66
    Vote Rating
    1
      0  

    Default Answered: Correct Way To Bind a Record to a Form?

    All,

    How do you bind a record to a form such that changes to the form fields modify the model?

    I see how you can call
    Code:
    form.setRecord(myRecord);
    , but that only manages getting the data out of the record into the form. Form -> record seems trickier, or at leas I see no automagical way to do it.

    The form documentation indicates that you can easily bind listeners to your form fields to auto-update on change, but it doesn't seem to be working. The part that isn't working is here:

    Code:
    var form = Ext.create('Ext.form.Panel', {
        listeners: {
            '> field': {
                change: function(field, newValue, oldValue) {
                    ed.set(field.getName(), newValue);
                }
            }
        },
        items: //as before
    });
    am i doing something weird, or does the above work for everyone? In the meantime, I've written this function in the form's initializer that does the same thing, but not nearly so elegantly.

    Code:
        initialize: function()    {
            Ext.each(this.query('> fieldset field'), function(field)
            {
                field.on('change', function(field, newValue, oldValue)
                {
                    this.getRecord().set(field.getName(), newValue);
                }, this);
            }, this);
        }
    Is there a better way?

    Thanks!

  2. You can use the updateRecord method on the form panel. This will go through all your fields and try to set the field value onto the record field. This updateReocrd method for some reason is not documented anymore, it was documented in past releases so I'm going to open a bug for that. Usage would be:

    Code:
    formpanel.updateRecord(formpanel.getRecord());

  3. #2
    Sencha User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,062
    Answers
    3976
    Vote Rating
    1391
      0  

    Default

    You can use the updateRecord method on the form panel. This will go through all your fields and try to set the field value onto the record field. This updateReocrd method for some reason is not documented anymore, it was documented in past releases so I'm going to open a bug for that. Usage would be:

    Code:
    formpanel.updateRecord(formpanel.getRecord());
    Mitchell Simoens @LikelyMitch
    Modus Create, Senior Frontend Engineer
    ________________
    Need any sort of Ext JS help? Modus Create is here to help!

    Check out my GitHub:
    https://github.com/mitchellsimoens

  4. #3
    Sencha Touch Premium User
    Join Date
    Oct 2010
    Location
    Portland, Maine USA
    Posts
    66
    Vote Rating
    1
      0  

    Default

    If the documentation for forms':

    Code:
    var form = Ext.create('Ext.form.Panel', {
        listeners: {
            '> field': {
                change: function(field, newValue, oldValue) {
                    ed.set(field.getName(), newValue);
                }
            }
        },
        items: //as before
    });
    is wrong, would you add a bug to fix that also?

    Thanks, Mitchell!

    John

Tags for this Thread

Posting Permissions

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