Reputation:
Greetings I have extended my admin add screen (tabularinline) by using the http://www.djangosnippets.org/snippets/1594/
Now I have a field in my model:
start = models.CharField(max_length=5)
this is intended as a special time format, it will be in a HH:MM format such as 16:30 . Now I want to implement a way that site auto assigns ":" between those numbers and for that I have found this jquery application: http://digitalbush.com/projects/masked-input-plugin/
When I check my admin add panel by firebug, I see that the field that I want to implement this masking function is:
<input id="id_outage_set-0-start" class="vTextField" type="text" maxlength="5" name="outage_set-0-start"/>
where "id_outage_set-0-start" is increased each time I add new.
Now I am looking for a way to implement these 2 together, I am a jquery newbie thus really lost at it.
Regards
Upvotes: 2
Views: 1136
Reputation: 1025
A good approach would be to define your own Widget, whose HTML rendering applies the JQuery mask.
Stuart Langridge gives some infos on how to change a field widget in the Admin interface : http://www.kryogenix.org/days/2008/03/28/overriding-a-single-field-in-the-django-admin-using-newforms-admin
That would be a good idea to package this into a small django app.
Upvotes: 0
Reputation: 17554
This should apply the mask plugin to all inputs with an id that begins with id_outage_set. Is that what you are after?
jQuery(function($){
$("input[id*='id_outage_set']").mask("99/99/9999",{placeholder:" "});
});
Upvotes: 1