Trailing comma in JavaScript

When trying to find a trailing comma error in JavaScript/JSON (mostly for Internet Explorer) regular expressions come in nicely. Search for the following:

,\s+}

It matches a comma followed by one or more whitespaces (tabs, spaces, line breaks), followed by a closing bracket.

It will not match the following (of course):

{
    property1: '123',
    property2: '456',
    //property3: '789'
}

But still, it’s a nice way of quickly searching for trailing comma errors.

Posted in Coding, ExtJS, Javascript | Leave a comment

ExtJS – Method previous is undefined

Having a ‘method.$previous is undefined’ error in ExtJS 4? You’re probably calling ‘callOverridden‘ instead of ‘callParent‘ when extending a class.

Ext.define('MyApp.controller.BaseController', {
    extend: 'Ext.app.Controller',
    myFunction: function() {
        console.log('myFunction in BaseController');
    }
});

Ext.define('MyApp.controller.SpecificController', {
    extend: 'MyApp.controller.BaseController',
    myFunction: function() {
         this.callOverridden(arguments);
         console.log('myFunction in SpecificController');
    }
});

This will show a “method.$previous is undefined” in the console. Function ‘callOverridden’ should be used when explicitly overriding a function using ‘override’:

MyApp.controller.BaseController.override({
    myFunction: function() {
        console.log('myFunction overridden');
        this.callOverridden(arguments);
    }
});

What should be used in the first example is:

Ext.define('MyApp.controller.SpecificController', {
    extend: 'MyApp.controller.BaseController',
    myFunction: function() {
         this.callParent(arguments);
         console.log('myFunction in SpecificController');
    }
});
Posted in Coding, ExtJS | Tagged , | Leave a comment

Unchecked checkbox in ExtJS 4

I’m currently in the process of converting a ExtJS 3 application to ExtJS 4. One of the things ExtJS 3 couldn’t do is submit the value of an unchecked checkbox. Checkboxes only have a value when they are checked.

Two situations where it’s nice to send an unchecked value to the server:

  • when sending deltas (the changed fields), the server-side code would never know if a checkbox was unchecked
  • when the form is dynamically generated and you want to prevent server-side code to find out if a checkbox was present and maybe unchecked

XCheckbox written by Jsakalos did a nice job for older versions of ExtJS.

In ExtJS 4 you can use the checkbox provided by the framework, just make sure you set the ‘uncheckedValue‘ property.

Example:

Ext.define('App.view.CheckTest', {
    extend: 'Ext.form.Panel',
    alias: 'widget.checktest',
    buttons: [{
        text: 'Submit',
        handler: function(button, event) {
            var form = button.up('form').getForm();
            form.submit();
        }
    }],
    defaultType: 'checkbox',
    items: [{
        boxLabel: 'Agree with TOS',
        inputValue: 'true',
        name: 'agreeTOS',
        uncheckedValue: 'false'
    }],
    title: 'Terms of service agreement',
    url: '/submitURL'
});

When leaving the checkbox unchecked it will submit “false”.

Posted in Coding, ExtJS, Javascript | Tagged , , | 1 Comment