Results 1 to 2 of 2

Thread: custom javascript class

  1. #1
    Sencha User
    Join Date
    Feb 2009
    Posts
    264

    Default custom javascript class

    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

  2. #2
    Sencha User
    Join Date
    Aug 2009
    Posts
    480

    Default

    You constructor is not handling the config.

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

    You can also do it in one statement like this:

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •