Showing posts with label Undefined. Show all posts
Showing posts with label Undefined. Show all posts

Wednesday, February 19, 2014

Raphael js - Uncaught TypeError: Cannot call method 'enable' of undefined

When enabling dragging in Raphael js, if you are using raphael-draggable, then you might run into following error when you try to enable the dragging on any element -

Uncaught TypeError: Cannot call method 'enable' of undefined

That line is -
 paper.draggable.enable() 

The issue is in Raphale 2.0 context is broken, and in order to fix that you have can add following function -

// to fix broken context issue with Raphael 2.0

Raphael.fn.fixNS = function(){

    var r = this;

    for (var ns_name in Raphael.fn) {

        var ns = Raphael.fn[ns_name];

        if (typeof ns == 'object') for (var fn in ns) {

            var f = ns[fn];

            ns[fn] = function(){ return f.apply(r, arguments); }

        }

    }

}
 
Once you add it, call that function below your Raphael block initialization -

var paper = new Raphael(obj.attr('id'), chart_width, chart_height);
    paper.fixNS();

This should be able to fix the issue and you will be able to enable dragging for individual element or your Raphael object.

paper.draggable.enable();

Thursday, January 9, 2014

Django 1.6 global name 'timezone' is not defined

If you are following the documentation to run the sample app, while doing date time comparison you might run into the issue on following code -

 def was_published_recently(self):
        return self.pub_date >= timezone.now() - datetime.timedelta(days=1)
    was_published_recently.admin_order_field = 'pub_date'
    was_published_recently.boolean = True
    was_published_recently.short_description = 'Published recently?'

It complains - global name 'timezone' is not defined

because it needs explicit import -

import datetime
from django.utils import timezone

Once you add it should be resolved. 

Sunday, November 4, 2012

Null Check in different language


Python - Null Check

15 or "default"       # returns 15
0 or "default"         # returns "default"
None or "default"    # returns "default"
False or "default"    # returns "default"

Django Template - None Check


{{obj.item_value|default_if_none:"smile"}}

C# - Null Check

var data = val ?? "default value";

Java - Null check

Foo f = new Foo();
DummyObj obj = new Obj().getSelection();
String str = obj != null ? f.format(obj) : "";

Javscript - Null/Undefined check

if (! param) param = "abc";
//other way to check this
if (param == null) is same as if(!param)


jQuery - Null/existence check

if ( $('#myDivObj').length ) {}

Feel free to add comments and other languages Null check mechanism (inline or explicit)