views:

243

answers:

3

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

A: 

Not sure I quite follow. Is this a simple case of selecting all the elements that you want to change and then running plugin functionality upon it?

Can you clarify?

James Wiseman
+1  A: 

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:" "});
});
Steerpike
Correct, but reading from the question I think the mask should be like "99:99"
Agos
the issue is, this only adds mask to the first input, but after I hit the add new button and select the new input box, it directs me back to the first input box.Thanks
A: 

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.

emel