One of my recent Ext JS 4 projects involved defining text areas with limits on the number ofwords that can be entered by the user.
I solved this problem by implementing a custom validation type (vtype) as illustrated below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
| Ext.apply(Ext.form.field.VTypes, { wordlimit : function(v, field) { v = v.replace(/(^\s*)|(\s*$)/gi,""); v = v.replace(/[ ]{2,}/gi," "); v = v.replace(/\n /,"\n"); var words = v.split(' ').length; var numremaining = field.maxWords - words; var fieldLabel = field.getFieldLabel(); fieldLabel = fieldLabel.substring(0, fieldLabel.indexOf('(') - 1); field.setFieldLabel(fieldLabel + " (" + numremaining + " words remaining" + " )"); if (words <= field.maxWords) { return true; } else { return false; } }, wordlimitText : "You exceeded the maximum number of words"}); |
You can apply the vtype to a textarea as illustrated below:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
| var config = { xtype: 'textareafield', fieldLabel: 'Describe yourself (50 word maximum)', labelAlign: 'top', allowBlank: false, name: 'description', anchor: '100%', resizable: true, resizeHandles: 's', vtype: 'wordlimit', maxWords: 50};panel.add(config); |
ligfecWverna_Baltimore Patrick Burrell https://wakelet.com/wake/_Zd2daMSf6SSpZ1psAS_S
ReplyDeleterecalnide
lincmotemp-go-1981 Jensen Alfonso ScreenHunter Pro
ReplyDeleteSlack
Sketchup
nodenkirchvab
riacaPerhi Diana Brown Click here
ReplyDeleteClick
cobbblacdanre