djangosnippets.org: Latest snippets tagged with 'forms'https://djangosnippets.org/tags/forms/2015-02-22T21:31:28-06:00Load dynamically loaded form javascript assets using dajax2015-02-22T21:31:28-06:00PhilipGarnerohttps://djangosnippets.org/snippets/10467/<p>I am used to load forms directly into modals using dajax but I found out I had to load the scripts using an ajax call from the browser.<br />
You can see here an example of a dynamically loaded form and the function used to load the scripts.</p>
Freely redistributableAnother Multiform2014-08-27T04:51:45-05:00dhkehttps://djangosnippets.org/snippets/3089/<p>MultiForm and MultiModelForm</p>
<p>Based on a PrefixDict class I wrote and thus very lean.
Lacks a little documentation, though</p>
Freely redistributableDjango forms add placeholder from help text template tag2014-05-17T11:14:13-05:00Ahmad.Dukhanhttps://djangosnippets.org/snippets/3050/<p>This snippet will change the field to include the placeholder in the field using the help_text attribute from the model or the form</p>
Freely redistributableA widget that renders JSON data as separate editable inputs.2013-07-16T19:53:06-05:00abbasovalexhttps://djangosnippets.org/snippets/2974/<p>You can see full examples on the page <a href="https://github.com/abbasovalex/django-SplitJSONWidget-form">GitHub</a></p>
Freely redistributableA Lazy ModelChoiceField implementation2013-07-16T12:13:39-05:00alecdoticohttps://djangosnippets.org/snippets/2973/<p>Sometimes we may need to generate a <em>ModelChoiceField</em> in which choices are generated at runtime, depending on the locale language. The snippet generates a <em>ChoiceField</em> based on a queryset and a specific attribute of the Model, ordering the choices by the attribute content in the locale language.</p>
<p><strong>Usage example</strong> (inside ...</p>
Freely redistributableInsert field attributes in template2013-05-10T05:53:45-05:00Sergio@Keyhttps://djangosnippets.org/snippets/2919/<p>Usage:</p>
<p><code>{%formfield form.description rows="3"%}</code></p>
Freely redistributableAutocomplete TextInput Widget w/ Static Data (jQuery UI)2013-03-15T14:26:29-05:00JoeLinuxhttps://djangosnippets.org/snippets/2901/<p>Custom form widget for rendering an autocomplete (using jQuery UI's autocomplete widget) text input in a template.</p>
<p>This arose from the need to have all fields asking for a state to use autocomplete, so I decided to make this.</p>
Freely redistributableCheckboxMultiSelect with interable checkboxes2012-11-02T08:52:07-05:00pyramids16https://djangosnippets.org/snippets/2841/<p>A widget for a checkbox multi select, adapted from the RadioSelect widget, which allows you to iterate over each choice in the template rather than outputting the whole thing as a ul in one go.</p>
<pre><code>{{ form.field.label_tag }}
{% for option in form.field %}
&lt;span&gt;{{ option }}&lt;/span&gt;
{% endfor %}
</code></pre>
Freely redistributableHTML5 Placeholder from FormField label2012-10-24T17:11:25-05:00Hillshumhttps://djangosnippets.org/snippets/2837/<p>This allows for easy generation of HTML5 placeholders based on a form_field's label. Use like so:</p>
<p>{% form_placeholder form.username %}</p>
Freely redistributableList all errors in a form +bootstrap highlighting2012-09-21T09:06:57-05:00ibrahimlawalhttps://djangosnippets.org/snippets/2823/<p>Use this snippet to list all errors in a form. The message will be shown in a boostrap-type alert which can be 'closed' using a dismiss button.</p>
<p>The <strong>field label</strong> and the <strong>error</strong> will be listed.</p>
<p>e.g.</p>
<blockquote>
<ul>
<li>Name: This field is required</li>
<li>Email: Please enter a valid email</li>
</ul>
</blockquote>
Freely redistributableShow all form errors2012-06-15T09:09:43-05:00timbroderhttps://djangosnippets.org/snippets/2769/<p>showing all the errors at the top of the page</p>
Freely redistributableMultiSelectField with comma separated values (Field + FormField)2012-05-17T17:23:26-05:00quinodehttps://djangosnippets.org/snippets/2753/<p>Daniel Roseman's snippet, updated will all fixes mentioned in the comments of the first version + some other things to make it work under Django 1.4.<br />
South, and dumpdata are working.</p>
<p>There's an ugly int(....) at the validate function in order to cast each value as an integer ...</p>
Freely redistributableMixin for named URL WizardViews with one form on the frontpage2012-03-05T16:58:46-06:00jezdezhttps://djangosnippets.org/snippets/2709/<p>A Django 1.4 wizard mixin for use cases with a wizard step on the frontpage
of your site -- with a request path of <code>'/'</code>.</p>
<p>Just define the name of the step (e.g. <code>root_step = 'landing_page'</code>)
and it does the setup and redirection automatically.</p>
Freely redistributableHandles Inline Formsets and also &quot;in-standard-way&quot; normal forms2012-02-27T00:09:48-06:00sebnapihttps://djangosnippets.org/snippets/2695/<p>If you read the docstring and the example you should get a clue what this Code does. I didn't want a big function everytime that handles every specific form, formset combinations so this how i can add/edit Models with specific Forms given to the magic_handle_inlineformsets function. It also ...</p>
Freely redistributableValidation for full e-mails (e.g. &quot;Joe Hacker &lt;joe@hacker.com&gt;&quot;)2011-12-21T02:43:32-06:00akaiholahttps://djangosnippets.org/snippets/2635/<p>Out of the box, Django e-mail fields for both database models and forms only accept plain e-mail addresses. For example, <code>joe@hacker.com</code> is accepted.</p>
<p>On the other hand, full e-mail addresses which include a human-readable name, for example the following address fails validation in Django:</p>
<pre><code>Joe Hacker &lt;joe@hacker ...</code></pre>
Freely redistributable