I'm new to Django and have been using django-bootstrap-form. I've been pretty happy with it, but I don't believe it provides a way to format the output for ".input-prepend" as described in Twitter Bootstrap's docs.
I'm guessing I'm going to have to override my input field's widget for this particular field. I'm not sure of the best way to do this, though. Any help would be appreciated.
You'll have to edit the templates, adding an if clause for prepending and possibly two more for appending or both cases at once or handle this with a templatetag (or beter even, the widget render method).
Have a look what's there to get the hang of it.
For the field itself either create a custom formfield or create a widget by wrapping a basic widget.
Related
I'm using a ModelForm to create multiple choice questions, and I want to apply a CSS class to a particular option (the "other" choice, in my case).
Is there a simple way to do this? It seems like it could theoretically be done with a custom widget, but I haven't been able to make a functional custom widget.
I am looking for a robust solution to implement a typeahead (Twitter typeahead) for a manytomany field. Basically, something identical to the tag input field here in StackOverflow.
The default widget for manytomany is a multiselect. However, since I want the user to provide new values, I need to use a inputText widget. My question is, what would be the best way to implement this functionality so that I can later pass an array of models instances to a cleaning stage?
In my cleaning stage I plan on doing a loop through the elements to check if they exist in the db, create them if they don't and apply validators to each elements.
My initial intuition was to use a hidden field that would receive the actual fields from the typeahead via javascript manipulation. Thus the input field would not be part of the model, just serve as an input box for the user.
Why reinvent the wheel. You can simply use django-taggit together with selectize.js. By using both of them, you don't even need any customization.
I am working on a django project with complex forms. In one of my form fields I need following functionality...... Its the text field. As the user starts typing the value the suggestions from existing database should appear in dropdown. Can anyone help me out with this ? Just similar to autocomplete but able to add new values.
This is going to be something in the JQuery/AJAX side of things, not Django. I would read up on the autocomplete functions of JQuery and use AJAX to call your DJango code and receive a populated list, which then displays to the user.
JQuery Autocomplete - Custom Data
If you don't want to deal with JavaScript, you can use a django application called django-autocomplete-light.
You can learn more about it (and get it) here: https://github.com/yourlabs/django-autocomplete-light
I am wondering how one would setup a multi-step form in CFWheels.
Clearly I would need to store form data in the session etc as I go, but I would like to know the best approach from a wheels perspective to do this the 'wheels way'.
Do I have just one action in my controller that handles this? Or would it be best to seperate each part of the form out into separate actions?
Advise on this and possible code examples would be much appreciated.
Thanks,
Michael
The way I've done it in past is use Ajax calls and a jquery modal.
though the jquery modal is not important, I just like the aesthetic. a simple div replacement will also work.
If you cannot be sure that the users can use AJAX then it won't work for you, but you might be able to use a popup window.
The advantage of using Ajax calls for multi-step forms is that you can adjust the form content from one step to another. Another advantage is that you don't have to store user data in the cache or session. Because each time you send a form, you can use the POST or GET.
For this to work, the quickest way of setting this up is to use the plugin called RemoteFormHelpers. Then each step of the form would be a different controller (or the same one with a switch statement based on the data passed)
I think this is a pretty versatile way of doing this, but you cannot do a form that uses file-uploads, well not easily as ajax won't let you do it without some serious pain.
I am building a custom image insert plugin for TinyMCE. The idea is that each article already has a relationship with a collection of images through an ArticleImage model which allows the user to provide an article-specific caption. The TinyMCE will then insert a custom tag (something like <myapp:image image-id="9389" caption="Caption override">) which is rendered as a preview of the image and caption in the editor, and rendered into <figure><img src="images/9389.jpg" /><figcaption>Caption override (Photo: photographer)</figcaption></figure>. This could equally be something like <myapp:poll> or <myapp:video>.
My question is: what is the best way (and where is the best place) to parse this 'dummy tag' into its rendered HTML in the Django view?
Or is there another, better approach?
IMHO, the best place to render custom markup, is in the template via a templatefilter.
I would risk myself to say that using a templatefilter to render custom markup is the "djangoish" way, since that's the way to go with django.contrib.markup.
Storing the custom tag in the model is a good idea, because then you can change the template filter implementation, which would be impossible if the custom tag is processed before storage.