1. #1
    Sencha User
    Join Date
    Feb 2013
    Location
    Sweden
    Posts
    13
    Vote Rating
    0
    Intraday is on a distinguished road

      0  

    Default Answered: Set value to text or number fields

    Answered: Set value to text or number fields


    Hello,

    -Controller
    MyController.js
    - View
    MyPanel

    I have created MyPanel.js in the view folder with some text and number fields and one button. In MyController.js I want to set different value to the fields in MyPanel every time someone push the button. Can you please tell me how I cant set values or disabe/enable the fields from the controller?

    Thanks in advance

  2. Try changing your selector to your alias

    Code:
    selector : 'myview'

  3. #2
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,085
    Answers
    675
    Vote Rating
    467
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      1  

    Default


    In your controller function, just get access to your for and then drill down:

    Code:
    refs : [
        {
             ref      : 'editForm',
             selector : 'myapp-user-edit'
        },
    ],
    // function
    Code:
    var me       = this,
        editForm = me.getEditForm(),
        field       = editForm.down('#field_user_name'); // itemId
    
    field.setValue('new value');

  4. #3
    Sencha User
    Join Date
    Feb 2013
    Location
    Sweden
    Posts
    13
    Vote Rating
    0
    Intraday is on a distinguished road

      0  

    Default


    Hello,
    Thank you for your reply. But it doesnt work when I try it.

    Quote Originally Posted by scottmartin View Post
    In your controller function, just get access to your for and then drill down:

    Code:
    refs : [
        {
             ref      : 'editForm',
             selector : 'myapp-user-edit'
        },
    ],
    // function
    Code:
    var me       = this,
        editForm = me.getEditForm(),
        field       = editForm.down('#field_user_name'); // itemId
    
    field.setValue('new value');

  5. #4
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,085
    Answers
    675
    Vote Rating
    467
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Please provide more detail .. where does it break? perhaps if you show your code.

  6. #5
    Sencha User
    Join Date
    Feb 2013
    Location
    Sweden
    Posts
    13
    Vote Rating
    0
    Intraday is on a distinguished road

      0  

    Default


    In MyView.js which is in the view directory I have this field userName.
    Here is a bit of my code:
    Code:
    Ext.define('myapp.view.MyView, {
        extend: 'Ext.panel.Panel',
        alias: 'widget.myview,    width: 400,
        title: 'Input',
        initComponent: function() {
            var me = this;
            Ext.applyIf(me, {
                items: [
                    {
                        xtype: 'fieldcontainer',
                        height: 292,
                        width: 300,
                        layout: {
                            type: 'absolute'
                        },
                        fieldLabel: '',
                        hideLabel: true,
                        items: [
                            {
                                xtype: 'textfield',
                                x: 35,
                                y: 45,
                                fieldLabel: 'UserName',
                                name: 'userName'
                            },
    I took your code and pasted to the MyContoller.js which is in the controller directory
    Code:
    refs : [
        {
             ref      : 'editForm',
             selector : 'myapp.view.MyView'
        },
    ],
    And paste it in a function:

    Code:
    var me       = this,
        editForm = me.getEditForm(),
        field       = editForm.down('#userName'); // itemId
    field.setValue('Test');

    When I run it. It says that the something is undefind.

  7. #6
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,085
    Answers
    675
    Vote Rating
    467
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      1  

    Default


    Try changing your selector to your alias

    Code:
    selector : 'myview'

  8. #7
    Sencha User
    Join Date
    Feb 2013
    Location
    Sweden
    Posts
    13
    Vote Rating
    0
    Intraday is on a distinguished road

      0  

    Default


    Thanks alot and God bless you!

    If I want to change several fields, should I repeat the same process?

  9. #8
    Sencha - Support Team scottmartin's Avatar
    Join Date
    Jul 2010
    Location
    Houston, Tx
    Posts
    9,085
    Answers
    675
    Vote Rating
    467
    scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future scottmartin has a brilliant future

      0  

    Default


    Sure .. not a problem.

Thread Participants: 1

Tags for this Thread