PDA

View Full Version : Proper/Minimalist Way To Handle Suppressing Enter Key In Text Area



rkanemeier
23 Jul 2013, 10:55 AM
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

slemmon
25 Jul 2013, 10:17 AM
The stripCharsRe config is probably your best bet:
http://docs.sencha.com/extjs/4.2.1/#!/api/Ext.form.field.TextArea-cfg-stripCharsRe



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/
}]
});

rkanemeier
31 Jul 2013, 12:09 PM
Thanks for your response. I used your example and created a working copy. Every time you press enter, it deletes the carriage return.

slemmon
31 Jul 2013, 1:34 PM
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/#!/api/Ext.util.Format-method-nl2br

rkanemeier
31 Jul 2013, 1:48 PM
actually, the stripCharsRe worked. the data being sent to the back-end program does not contain invalid display characters.