• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Announcement

Collapse
No announcement yet.

Loading a form

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Loading a form

    Quick question about the form loading in the auto code example programs.

    The auto-code applications use an Ajax request, and loads the data into the form in the success callback using form.setValues().
    There's also a call to the encodeProperties function that's doing something with response.root:

    Code:
      Ext.Ajax.request({
          url: '/valence/vvcall.pgm',
          params: {
             pgm: 'AC1021',
             action: 'getRec',
             VVRRN: VVRRN
          },
          success: function(response) {
             var r = Ext.decode(response.responseText);	
             r.rec = app.encodeProperties(r.rec);
             if (r.success) {
                windowform.setValues(r.rec);
             } else {
                Valence.util.Helper.msg('Error', 'Could not load record');
             }
          }
      });

    I was thinking about using the form.load() to do this instead; it seems simpler to me this way:

    Code:
      form.load({
        url: '/valence/vvcall.pgm',
        params: {
          pgm: 'AC1021',
          action: 'getRec',
          VVRRN: VVRRN
        },
      });
    Before I change how the forms are loaded I was wondering:
    1) What is the encodeProperties doing?
    2) Is there a compelling reason to use this approach over using form.load()?

    Here's the encodeProperties function which has been added to the Application object (I don't understand what it's purpose is):
    Code:
        encodeProperties: function(obj) {
            var mapObj = {
                "#":"p",
                "$":"s",
                "@":"a"
            };
            Ext.Object.each(obj,function(prop,val){
                text = prop;
                text = text.replace(/#|\$|@/g, function(matched){
                    return mapObj[matched];
                });
    
                if (text !== prop){
                    delete obj[prop];
                    obj[text] = val;
                }
            });
            return obj;
        },

  • #2
    The "form.load" approach should work as well. However, I do believe that it will pass you different parameters to the "success" (the form object and an "action" object).

    So you could do something like:

    Code:
    form.load({
        url : 'xxxxx',
        params : {
            abc : 123
        },
        success : function(form,action){
           var r = Ext.decode(action.response.responseText);
           etc.....
        }
    It looks like the "encodeProperties" method is ensuring that there are no #, $,or @ characters in the name of any field. If you do not have any you can safely omit this call.

    Comment

    Working...
    X