PDA

View Full Version : custom javascript class



Stephan123
1 Nov 2011, 1:39 AM
Hello !

In the moment i test custom javascript classes.
Here my example:


Ext.namespace('Samples');

Samples.Form = function(){
this.counter = 0;
Samples.Form.superclass.constructor.call(this);
};

Ext.extend(Samples.Form, Ext.form.FormPanel, {
addCounter: function(){
this.counter++;
},
getCounter: function(){
return this.counter;
},
testCounter: function(){
alert('Counter: ' + this.counter);
}
});

var simple = new Samples.Form({
labelWidth: 75,
url:'save-form.php',
frame:true,
title: 'Simple Form',
bodyStyle:'padding:5px 5px 0',
width: 350,
defaults: {width: 230},
defaultType: 'textfield',

items: [{
fieldLabel: 'First Name',
name: 'first',
allowBlank:false
},{
fieldLabel: 'Last Name',
name: 'last'
},{
fieldLabel: 'Company',
name: 'company'
}, {
fieldLabel: 'Email',
name: 'email',
vtype:'email'
}, new Ext.form.TimeField({
fieldLabel: 'Time',
name: 'time',
minValue: '8:00am',
maxValue: '6:00pm'
})
],

buttons: [{
text: 'Save'
},{
text: 'Cancel'
}]
});

simple.render(document.body);

When i test i see only a blue line.
In the firebug console there is not an error.

Who can help ?

Your sincerly

Stephan

plalx
1 Nov 2011, 6:44 AM
You constructor is not handling the config.


Samples.Form = function (config) {
this.counter = 0;
Samples.Form.superclass.constructor.call(this, config);
};


You can also do it in one statement like this:


Samples.Form = Ext.extend(..., {
constructor: function(config) {...}
});