PDA

View Full Version : default values for a textfield or number field ?



muncher
11 Oct 2010, 10:42 AM
I have a textfield and I want to set default value for that field. However, emptyText or value attributes are not helping. Is there any other attribute to set ?



Ext.myApp.form.TextField.FamilySize = Ext.extend(Ext.form.NumberField, {
initComponent : function(config) {

Ext.apply(this, {
name:'famsize',
fieldLabel : 'Family Size',
hiddenName : 'famsize',
anchor:'50%',
value:0,
emptyText:"0"
});//end of ext.apply
Ext.myApp.form.TextField.FamilySize.superclass.initComponent.apply(this,
config);
} //end of initconfig

muncher
11 Oct 2010, 10:49 AM
Oops.. move this thread to help forum.

laurentParis
11 Oct 2010, 9:44 PM
value is great !
I test your code and numberfield have a default value...

muncher
13 Oct 2010, 9:48 AM
Right, you can see those textboxes initialized appropriately. However, when u iterate over the form fields and one the field being the above number field, field.getValue() or field.getRawValue returns "" instead of default value.

Condor
13 Oct 2010, 10:57 AM
Specify value:0, but NOT emptyText:'0'.

jtpacheco
13 Oct 2010, 11:18 AM
Correct me if I'm wrong, but when using fields with forms, don't you need to mess around with the hiddenValue attribute?

Condor
13 Oct 2010, 11:21 AM
hiddenValue can be useful for initializing a combobox (with a hiddenName).

jtpacheco
13 Oct 2010, 11:25 AM
Quite right, wasn't sure if it extended to all form-type fields. Carry on :)

muncher
13 Oct 2010, 11:50 AM
Ok that works. But am a bit confused as to why don't we have a default value. I mean ideally the functionality should be that whenever there is not data entered the value of 0 should be assumed in this case.

Now, yes as per the solution, it sets the value to zero, but when the user erases that text, it is again empty. The point being default value should be used when no value is set, or am i missing something ?

Condor
13 Oct 2010, 11:56 AM
Ext fields don't have a defaultValue. If you want default values then you could use applyIf to override empty values before submitting.