how to set Value for extjs textfield?
Asked Answered
O

3

12

i have a lot of textfields for userdata. and i wish to set it from DB.

items: [{
                        xtype: "form",
                        bodyPadding: 5,
                        border: false,
                        defaults: {
                            xtype: "textfield",
                            inputType: "text",
                            anchor: "100%"
                        },
                        items: [{
                            fieldLabel: 'Username:',
                            readOnly: true,
                            value: 'Admin',
                            name: "username"
                        }, {

i have external class named openDB.js with method getUserByUsername() here is small code how its will be used in other view and it works, but in my actuall view i cant set the Value of textfield. please help how to do that?

 openDB.getUserByUsername(user.username).then(function(userDetails) {
            me.setTitle("Welcome " + userDetails.mail + "!");
        });

i want to do something like this with value: 'Admin' and so on...

i found some method on Sencha Forum, but can I use it??

setValue: function(value) {
        var me = this;
        me.setRawValue(me.valueToRaw(value));
        return me.mixins.field.setValue.call(me, value);
    },
Odeen answered 13/8, 2013 at 16:17 Comment(0)
O
38

after couple hours of fighting with that -> BEST SOLUTION EVER:

items: [{
                        fieldLabel: 'Username:',
                        id: 'usernameID',
                        readOnly: true,
                        value: user.username,
                        name: "username"
}]
... 
var name = Ext.getCmp('usernameID').setValue('JohnRambo');
Odeen answered 14/8, 2013 at 12:40 Comment(1)
Excellent, if you have a number of them you can: Ext.Object.each(values, function(key, value) { Ext.getCmp(key).setValue(value); });Twiggy
R
1

Why not just set up a model and store for your form and use the loadRecord method?

Remedial answered 14/8, 2013 at 11:44 Comment(1)
loadRecord() function expects a single record correct? The state of the Ext.store, data might be dessimilar from that of the form.Twiggy
D
-2

It works for me:

ELEMENT.inputEl.dom.value = "000000";
Dimitry answered 9/10, 2018 at 13:5 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.