tags:

views:

30

answers:

1

Is it possible to make django's (v1.2) URLField output an HTML5 input tag where type="url"?

------------- SOLUTION -------------

from django.forms import ModelForm
from django.forms import widgets
from django.forms import fields
from models import MyObj

class URLInput(widgets.Input):
    input_type = 'url'

class MyObjForm(ModelForm):
    url = fields.URLField(widget=URLInput())

    class Meta:
        model = MyObj
A: 

You have to create a custom widget for that.

class URLInput(forms.TextInput):

    input_type = 'url'

Then you can pass this widget to URLField constructor:

class MyForm(forms.Form):

    url = forms.URLField(widget=URLInput())
Andrey Fedoseev
Hmm, it didn't work. I got `ViewDoesNotExist ... Error was: 'module' object has no attribute 'URLField'`.I'm adding this to a model form. Do I need to do something different?
Roger
OK, I've got it. I'll update my question with the solution. Thanks.
Roger