Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filefield with extjs 4.2 without fakepath

I want with extjs 4.2

I use this component in attachment :

{
    xtype: 'filefield',
    id: 'file6',
    fieldLabel: 'test ',
    labelWidth: 100,
    msgTarget: 'side',                  
    allowBlank : false,
    anchor: '100%',
    buttonText: 'upload'
},

I want to have a attachment component which display name of file without this text : c /fakepath

like image 538
franco Avatar asked Dec 08 '22 09:12

franco


2 Answers

There isn't a built-in way to accomplish this however, you can do a find/replace for fakepath and remove. I impelmented this on the change event. Here is an example:

listeners: {
                        change: function(fld, value) {
                            var newValue = value.replace(/C:\\fakepath\\/g, '');
                            fld.setRawValue(newValue);
                        }
                    }

I created a sencha fiddle demonstrating a working example

like image 115
weeksdev Avatar answered Dec 23 '22 18:12

weeksdev


Similar to user3550464's answer, but in a whole lot less code:

Add this to your file field listeners object. This code will remove all text up to and including the last slash or backslash in the field.

change: function (field, value) {
    'use strict';
    var newValue = value.replace(/(^.*(\\|\/))?/, "");
    field.setRawValue(newValue);
}
like image 38
Nisengo Avatar answered Dec 23 '22 17:12

Nisengo