Results 1 to 4 of 4

Thread: Simple TextArea Question

  1. #1
    Sencha User
    Join Date
    Sep 2009
    Posts
    28
    Vote Rating
    1
      0  

    Default Simple TextArea Question

    Ugh. I hate it when I get stuck for hours on something that is incredibly simple.

    I have been away from JavaScript for a while.

    I have done numerous Google Searches as well as searching for 5+ pages of the forums for "textarea" and similar things. So, forgive me if this is easy to find on search, I must have failed to put the correct search terms.

    Creating a window...

    Code:
    layout: 'border',
    items:[{
      xtype: 'form',
      border: false,
      padding: 0,
      layout:'fit',
      keys: [{
        key: [Ext.EventObject.ENTER],
        handler: function() {
          var chat = Ext.getCmp('chat-msg');
          Ext.getCmp('chatbox').body.insertHtml('beforeEnd','You: ' + chat.getValue() + '<br />');
          chat.setText('');
        },
      }],
      items: [{
        xtype: 'textarea',
        name: 'chat-msg',
        id: 'chat-msg',
      }],
      region:'south',
      elements:'body',
      height:40,
      split:true
    },{
      autoScroll:true,
      elements:'body',
      region:'center',
      id:'chatbox',
    }],
    So the above is what I think is relevant. It creates what I want, a blank area in center panel, with a full fit textarea in the south panel.

    The handler works decently, when I press "enter" it adds "You: <your text>" to the top panel.

    But, I can't figure out how to clear the text in the textarea box. I've tried setValue(''), reset(), setText(''), and tried searching... this is so simple yet I can't figure it out.

    Also, I'm not sure if that's the most elegant way to get the chat inserted if there is feedback on that too.

    Thanks.
    Last edited by Dustin Graham; 2 Mar 2011 at 1:39 AM. Reason: Thought I hit "preview" but I guess not. Updated now. Thanks.

  2. #2
    Sencha User
    Join Date
    Sep 2009
    Posts
    28
    Vote Rating
    1
      0  

    Default

    I'm pretty sure I clicked "Preview Post" and it appears to have posted it...

    I am editing my first post. I am not done asking my question.

    First post updated with my full question. Sorry about the double post.

  3. #3
    Sencha User
    Join Date
    Sep 2009
    Posts
    28
    Vote Rating
    1
      0  

    Default

    Not sure what's going on here, but I reorganized it a bit, and got it working. I think my solution was adding the scope: this, but I don't fully understand it yet.

    Code:
    layout: 'border',
    				items:[{
    					xtype: 'form',
    					border: false,
    					padding: 0,
    					layout:'fit',
    					keys: [{
    						key: [Ext.EventObject.ENTER],
    						handler: this.handleChat,
    						scope: this,
    					}],
    					items: [{
    						xtype: 'textarea',
    						name: 'chat-msg',
    						id: 'chat-msg',
    					}],
    					region:'south',
    					elements:'body',
    					height:40,
    					split:true
    				},{
    					autoScroll:true,
    					elements:'body',
    					region:'center',
    					id:'chatbox',
    				}],
    And

    Code:
    	handleChat: function(key, e) {
    		var chat = Ext.getCmp('chat-msg');
    		Ext.getCmp('chatbox').body.insertHtml('beforeEnd','You: ' + chat.getValue() + '<br />');
    		chat.setValue('');
    		e.stopEvent();
    	},
    I guess I needed the scope for some strange reason... then after I created the scope and separate function it seemed to work. I was left with a newline which is why I added the e.stopEvent() which prevented the newline.

    This is working nicely now.

  4. #4
    Sencha User Condor's Avatar
    Join Date
    Mar 2007
    Location
    The Netherlands
    Posts
    24,246
    Vote Rating
    133
      0  

    Default

    Can't be the scope. You're not use 'this' inside the handleChat method...

Similar Threads

  1. Very noob question: Creating a simple form, very simple form with designer
    By altamirador in forum Ext Designer: Help & Discussion
    Replies: 1
    Last Post: 27 May 2010, 5:16 AM
  2. Simple way to do autocpmlete in textarea
    By HemantPagare in forum Ext 2.x: User Extensions and Plugins
    Replies: 2
    Last Post: 7 Apr 2009, 5:37 AM
  3. Simple insertion of textarea into the DOM
    By fernando in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 8 Sep 2007, 2:38 PM
  4. Simple question about TextArea auto-expanding
    By Topper in forum Ext 1.x: Help & Discussion
    Replies: 1
    Last Post: 8 Sep 2007, 12:20 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
  •