Page 1 of 2 12 LastLast
Results 1 to 10 of 13

Thread: Checkbox can't be edited within Ext JS

  1. #1
    Sencha User
    Join Date
    Jun 2008
    Posts
    12

    Default Checkbox can't be edited within Ext JS

    I have a checkbox in an Ext.form.formPanel container:
    Code:
    ... (removed code for better reading)
    items: {
            xtype: 'checkbox',
            boxLabel: 'addSerialNumber',
            id: 'addSerialNumber',
            name: 'addSerialNumber',
            checked: true
        }
    ... (removed code for better reading)
    Later on I try to manipulate/edit this checkbox:
    Code:
    Ext.getCmp("addSerialNumber").setValue(false);
    I get the following Java Script error:
    TypeError: Property 'setValue' of object [object Object] is not a function

    Why this?

  2. #2
    Sencha User
    Join Date
    Aug 2010
    Posts
    177

    Default

    That should work. Are you sure that you don't have duplicate id?
    --
    Mehmet ad?rc?

  3. #3
    Sencha User Screamy's Avatar
    Join Date
    Jun 2008
    Posts
    244

    Default

    Hard coded ids make your app a lot more brittle. Try using 'ref' instead, where this will allow you to use object/property notation. Note that 'ref' values are not global; they're scoped within the chain of objects where defined:

    Code:
    var form = new Ext.form.FormPanel({
      ref: 'form',
      items: [{
         xtype: 'checkbox',
         boxLabel: 'addSerialNumber',
         ref: 'addSerialNumber',
         name: 'addSerialNumber',
         checked: true
      }]
    });
    
    var window = new Ext.Window({
      height: 200,
      width: 300,
      items: [form]
    });
    
    window.show();
    
    // Here's how you would access the checkbox.
    window.form.addSerialNumber.setValue(true);

  4. #4
    Sencha User
    Join Date
    Jun 2008
    Posts
    12

    Default

    You showed me the way!

    I changed the id from "addSerialNumber" to "addSerialNumber2" and all works now. I'm sure, there is no other object in the HTML with the id "addSerialNumber".

    Dubious?

  5. #5
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379

    Default

    That's why you shouldn't use ids. Not sure last time I actually needed to set an id
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  6. #6
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379

    Default

    I also deleted the other duplicate 4 threads. Make sure you don't post more than one.
    Last edited by mitchellsimoens; 12 Apr 2011 at 6:14 AM. Reason: Updated number of duplicate threads.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  7. #7
    Sencha User
    Join Date
    Jun 2008
    Posts
    12

    Default

    Quote Originally Posted by Screamy View Post
    Hard coded ids make your app a lot more brittle. Try using 'ref' instead, where this will allow you to use object/property notation. Note that 'ref' values are not global; they're scoped within the chain of objects where defined:
    Thanks, this example works.

    I tried it in my app: Because there are more nested containers, it's not simple to define all the refs and access the checkbox at least.

  8. #8
    Sencha Premium User mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    40,379

    Default

    Quote Originally Posted by vektor7 View Post
    Thanks, this example works.

    I tried it in my app: Because there are more nested containers, it's not simple to define all the refs and access the checkbox at least.
    It will benefit you and your app to put in the work to get it to work without setting ids.
    Mitchell Simoens @LikelyMitch

    Check out my GitHub:
    https://github.com/mitchellsimoens

    Posts are my own, not any current, past or future employer's.

  9. #9
    Sencha User
    Join Date
    Jun 2008
    Posts
    12

    Default

    It will benefit you and your app to put in the work to get it to work without setting ids.
    Thanks for this really interesting statement.

    I will try it!

  10. #10
    Ext JS Premium Member
    Join Date
    Jul 2009
    Posts
    239

    Default

    Hm, I use ids a lot to help me with my selenium tests.
    Sure, you need to be careful not to use the same ids twice, but that's usually not that hard.
    ExtJS 4 plugins:
    varheaders - short/normal/long column header
    clearbutton - mouseover clear button in text field
    Blog: fit4dev
    ExtJS User Group Hamburg

Page 1 of 2 12 LastLast

Similar Threads

  1. Can A TreeTable Be Edited?
    By ccocco in forum Ext GWT: Help & Discussion (1.x)
    Replies: 2
    Last Post: 8 Apr 2009, 1:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •