Search code examples
extjsfilefield

Placing a filename in a filefield in extjs


In my store I have a field called CreditName. In my view I am trying to check if CreditName is not null and if it is not enter it into my filefield. I have added a listener to my filefield that will enter text into the filefield. What I am having trouble with is getting CreditName into the filefield. I know that it is reading from my store because other fields are appearing properly.

Here is my code for my filefield

 xtype: 'filefield',
        buttonText: 'Select A File',
        fieldLabel: 'File',
        name: 'Credit',
        labelWidth: 50,
        msgTarget: 'under',
          return true;
        },
        listeners: {
          render: function (comp) {
            comp.setRawValue(CreditName);
          }
        }

Here is the store code

fields: [ {
    name: 'PartyId',
    type: 'string'
  }, {
    name: 'CreditName',
    type: 'string',
    critical: true
  }],
  proxy: {
    type: 'ajax',
    url: 'api/parties',
    reader: {
      type: 'json'
    }
  }

PartyId shows up fine, here is the code for that, it is in the same view as filefield

     {
        xtype: 'displayfield',
        name: 'PartyId',
        fieldLabel: ' Party ID'
      },

Solution

  • In your config of 'filefield', you have to use same name as 'name' property in store. In your case, it should be name: 'CreditName', not 'Credit'.

    --edit--

    You can get model values in 'render' listener like this:

    render: function (comp) {
        var model = comp.getModelData(),
            value = model.get('CreditName');
        comp.setRawValue(value);
    }