Archive for June, 2009

Add confirm dialog to a link with jQuery

Here’s another simple jQuery snippet I like to add to my projects. This will allow you to present a javascript confirm dialog when a user clicks on a link or a submit button with a confirm attribute it. The value of the confirm attribute will be the text displayed in the confirm dialog box. I often use this for delete button so the user has a chance to back out.

$(function() {
    $("a[confirm], input[type=submit][confirm]").click(function() {
        conf = confirm($(this).attr("confirm"));
        if(!conf)
            return false;
    });
}

Turn table rows and buttons into clickable links with jQuery

This simple little script often comes in quite handy when I’m working on a web app. It allow you to add an href attribute to tr, td, or input[type=button] tags to make them clickable links

$(function() {
    $("input[type=button][href], tr[href], td[href]").click(function() {
        location.href = $(this).attr("href");
    });
});

Dynamically change field attributes in a Django ModelForm

I’ve encountered situations using Django’s ModelForm where I’ve needed the form to validate differently then the default behavior in various instances. Here’s an example of how I changed all the fields from the default of not being required to all being required without much effort:

class AddressRequiredForm(forms.ModelForm):

    def __init__(self, *args, **kwargs):
        super(AddressForm, self).__init__(*args, **kwargs)
        for name, field in self.fields.iteritems():
            if name not in ['address2',]:
                field.required = True

    class Meta:
        model = Address

This is pretty simple, but it saved me a lot of time by not having to re-type each field name with a new set of properties.

Hello World

I’m testing out this Django based blog engine named byteflow. I was considering starting my own from scratch, but I really don’t have the time to pump out anything half decent. I came across this engine and decided to start from there.

The only requirement I had for a blog engine was for it to use the Django framework. I spend (almost) every day writing code using django, so I wanted something I would feel comfortable modifying. So here I am.. hopefully this site will help me to organize my thoughts.

This is primarily a place for me to record and recall ideas and information, so content you may see here (if any) will likely be scattered with no underlying theme.

I will probably keep comments open for anyone to post until I start seeing spam. So feel free to share your thoughts.


 Luke