PDA

View Full Version : get size of text value



mgoodi
28 Jun 2016, 4:10 AM
I've been trying to get the length of a value in a text box, using

var dob = Ext.getCmp('date_of_birth_year').size;
as I only want to trigger a function if I have a length of 4.
I have an alert set to show the value of dob on the keyup, but no matter the length, I always get a value of 20.

Where am I going wrong?

joel.watson
28 Jun 2016, 4:48 AM
Hi--

You would want to first use getValue() to retrieve the value from the textfield, and then evaluate the length of that string.

Thanks
Joel

mgoodi
28 Jun 2016, 7:21 AM
Thanks Joel.

I used the following, but had to get the string value first.

var dob = Ext.getCmp('date_of_birth_year').getValue().toString();
var dobSize = dob.length;

joel.watson
28 Jun 2016, 7:27 AM
Hi--

It's working for me (see Fiddle): https://fiddle.sencha.com/#fiddle/1cpn

Thanks
Joel

mgoodi
28 Jun 2016, 7:30 AM
Hi Joel,

I had to use toString() first, and then it worked.

Thanks!