Login

Disable fields in oldforms admin using jQuery

Author:
schraal
Posted:
June 17, 2008
Language:
JavaScript
Version:
Not specified
Tags:
admin jquery oldforms disable
Score:
0 (after 0 ratings)

This snippet shows how to disable fields in a edit page in the oldforms admin using jquery.

The idea is to add the javascript to the edit page using the js attribute of the model's Admin class. In this case jQuery and a custom javascript file are added.

The javascript sets the disabled attribute of the name field to true as soon as the document is ready.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
Model:

class Placeholder(models.Model):
    name=models.CharField()
    description = models.CharField(blank=True, maxlength=200)
 
    class Admin:
        list_display = ('name', 'description')
        js = (
              '/appmedia/js/jquery.js',
              '/appmedia/js/placeholder.js',
              )

placeholder.js:

$(document).ready(function(){
   $('#id_name').attr("disabled", true);
});

More like this

  1. Orderable inlines using drag and drop with jQuery UI by simon 6 years, 5 months ago
  2. admin: edit related object shortcut by christian 7 years, 5 months ago
  3. "Save and Continue" keyboard command for admin, with autoscroll by jcushman 5 years, 1 month ago
  4. Adding buttons to submit line in a Admin page by marinho 6 years, 9 months ago
  5. Allow editing of the selected object of the filter_vertical/filter_horizontal widget with jquery by jpic 6 years, 4 months ago

Comments

miguelvel18 (on October 8, 2009):

when the field is disabled,web form shows a error message of validation because the field is required. The field have a default value, but shows a error message validation, help me

#

Please login first before commenting.