Results 1 to 5 of 5

Thread: Proper/Minimalist Way To Handle Suppressing Enter Key In Text Area

  1. #1
    Sencha User
    Join Date
    May 2010
    Location
    Dallas, TX
    Posts
    69
    Answers
    6

    Default Answered: Proper/Minimalist Way To Handle Suppressing Enter Key In Text Area

    I have a form that has a text area. When the user presses enter, and the form is submitted, the carriage return is messing up our back-end data. I could scrape the invalid values out of the incoming data, however, I'd like to see if there is a way to either:

    1. prevent the enter key from being pressed in the textarea
    2. create a textfield that allows word wrapping
    3. scrape the invalid values (enter key) out of the value being passed to the backend program

  2. Thanks for your response. I used your example and created a working copy. Every time you press enter, it deletes the carriage return.

  3. #2
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505

    Default

    The stripCharsRe config is probably your best bet:
    http://docs.sencha.com/extjs/4.2.1/#...g-stripCharsRe

    Code:
    Ext.create('Ext.form.FormPanel', {
        title      : 'Sample TextArea',
        width      : 400,
        bodyPadding: 10,
        renderTo   : Ext.getBody(),
        items: [{
            xtype     : 'textareafield',
            grow      : true,
            name      : 'message',
            fieldLabel: 'Message',
            anchor    : '100%',
            enableKeyEvents: true,
            stripCharsRe: /\n||\r/
        }]
    });

  4. #3
    Sencha User
    Join Date
    May 2010
    Location
    Dallas, TX
    Posts
    69
    Answers
    6

    Default

    Thanks for your response. I used your example and created a working copy. Every time you press enter, it deletes the carriage return.

  5. #4
    Sencha User slemmon's Avatar
    Join Date
    Mar 2009
    Location
    Boise, ID
    Posts
    6,165
    Answers
    505

    Default

    I think I see what you're saying now. Within the submit logic you might want to use the nl2br formatting method before sending the form data to your server:
    http://docs.sencha.com/extjs/4.2.1/#...t-method-nl2br

  6. #5
    Sencha User
    Join Date
    May 2010
    Location
    Dallas, TX
    Posts
    69
    Answers
    6

    Default

    actually, the stripCharsRe worked. the data being sent to the back-end program does not contain invalid display characters.

Posting Permissions

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