Thanks for the advice, that's very useful. Do other developers consider it vital to support non-javascript browsers for accessibility reasons? Or are people largely using ajax regardless of accessibility, to make their apps look shiny?
Regards, Chris. On 6 May, 16:07, Matthias Kestenholz <matthias.kestenh...@gmail.com> wrote: > Hey, > > > > On Wed, May 6, 2009 at 3:27 PM, Chris Dew <cms...@googlemail.com> wrote: > > > I'd like to develop a Django application with the following > > properties: > > > A page (list of items) will have a link to a page with a form to add a > > new item. > > > If there is no javascript, the link will take the user to the new page > > and let the user submit the form, then return them to the initial page > > when the form successfully validates. > > > If there is javascript, the link will open the form *within* the > > current page (via ajax, perhaps as thickbox or greybox). Submission/ > > validation errors of/on the form will take place entirely within the > > current page. When the for is submitted and valid, the form's div > > will disappear/close. > > > At the moment, I think that I need to have ajax and non-ajax views for > > *each form* within the application. > > > I also need to code form template snippets (for ajax) for *each form* > > which are included by the templates for the non-ajax pages. > > > Has anyone developed a Django extension which makes this easier - some > > form of 'unajax for non javascript-capable browsers'. > > > I realise that I'll probably need to do this myself, by hand, but I > > thought I'd ask the question, just in case. > > Just to give you some ideas (it really is not that hard): > > def your_view(request): > # your processing code > > if request.is_ajax(): > return render_to_response('_form.html', {}...) > else: > return render_to_response('form.html', {}...) > > Your form.html template should contain not much more than the following code: > > {% extends "base.html" %} > > {% block content %} > <div id="form"> > {% include "_form.html" %} > </div> > {% endblock %} > > If you use the jQuery form plugin (it's what I know, not what I want > to advertize -- I'm sure every javascript library has the bestest way > to do it), you can prepare your form like this: > > $('#form form').ajaxForm({'target': '#form'}) > > So in closing, you'll need several templates which are only used if > the client does not support javascript; there is still some code > duplication around, but not too much anymore, because you can reuse > the view code and the _form.html template. > > I hope this'll put you on track. > Matthias --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---