-
Notifications
You must be signed in to change notification settings - Fork 398
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
119 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
from django import forms | ||
|
||
|
||
class AllElementsForm(forms.Form): | ||
text_input = forms.CharField(help_text="Sample text input") | ||
another_input = forms.CharField(show_hidden_initial=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
{% load viewflow %} | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta http-equiv="X-UA-Compatible" content="IE=edge"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1"> | ||
<title>Form Sample Template</title> | ||
|
||
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css"> | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="page-header"> | ||
<h1>Form example</h1> | ||
</div> | ||
|
||
<form method="POST"> | ||
{% viewform 'unit/form_layout.html' %} | ||
{% endviewform %} | ||
</form> | ||
|
||
<div class="page-header"> | ||
<h1>Standard django</h1> | ||
</div> | ||
|
||
<form method="POST"> | ||
<table> | ||
{{ form.as_table }} | ||
</table> | ||
</form> | ||
</div> | ||
|
||
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> | ||
<script src="//netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js"></script> | ||
</body> | ||
</html> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{% load viewflow %} | ||
|
||
{% for field in form.visible_fields %} | ||
{% viewpart field field.html_name %} | ||
{% viewfield field %} | ||
{% endviewpart %} | ||
{% endfor %} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
{% include 'viewflow/form/field_errors.html' %} | ||
<label class="control-label"> | ||
{{ field.label }} | ||
<input type="text" class="form-control" name="{{ field.name }}" id="id_{{ field.name }}" value="{{ field.value }}" > | ||
<div class="form-group"> | ||
{% include 'viewflow/form/field_errors.html' %} | ||
<label for="{{ field.id_for_label }}" class="control-label"> {{ field.label }} </label> | ||
<input type="text" class="form-control" name="{{ field.name }}" id="id_{{ field.name }}" {% if field.value %}value="{{ field.value }}"{% endif %}> | ||
{% if field.help_text %} | ||
<p class="help-text">{{ field.help_text }}</p> | ||
{% endif %} | ||
</label> | ||
{{ hidden_initial }} | ||
</div> | ||
<br/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,71 @@ | ||
from singledispatch import singledispatch | ||
from django.forms import widgets | ||
from django.template import Context | ||
from django.template.loader import get_template | ||
|
||
|
||
@singledispatch | ||
def render_widget(widget, name, value, attrs=None): | ||
return widdget.render(name, value, attrs=attrs) | ||
def render_widget_template(bound_field, template_name, widget=None, attrs=None): | ||
""" | ||
Renders field depends on widget template | ||
""" | ||
if widget is None: | ||
widget = bound_field.field.widget | ||
|
||
if bound_field.field.localize: | ||
widget.is_localized = True | ||
|
||
@render_widget.register(widgets.TextInput) | ||
def _(widget, name, value, attrs=None): | ||
pass | ||
attrs = attrs or {} | ||
auto_id = bound_field.auto_id | ||
|
||
if auto_id and 'id' not in attrs and 'id' not in widget.attrs: | ||
attrs['id'] = auto_id | ||
|
||
hidden_initial = '' | ||
if bound_field.field.show_hidden_initial: | ||
hidden_initial = bound_field.as_hidden(only_initial=True) | ||
|
||
template = get_template(template_name) | ||
return template.render(Context({ | ||
'field': bound_field, | ||
'widget': widget, | ||
'id': auto_id, | ||
'hidden_initial': hidden_initial | ||
})) | ||
|
||
@render_widget.register(widgets.Textarea) | ||
def _(widget, name, value, attrs=None): | ||
pass | ||
|
||
@singledispatch | ||
def render_widget(widget, bound_field, attrs=None): | ||
result = bound_field.as_widget(attrs=attrs) | ||
if bound_field.field.show_hidden_initial: | ||
result += bound_field.as_hidden(only_initial=True, attrs=attrs) | ||
return result | ||
|
||
|
||
@render_widget.register(widgets.TextInput) | ||
def _(widget, bound_field, template_name='viewflow/form/widgets/text_input.html', attrs=None): | ||
return render_widget_template(bound_field, template_name=template_name, attrs=attrs) | ||
|
||
@render_widget.register(widgets.CheckboxInput) | ||
def _(widget, name, value, attrs=None): | ||
pass | ||
|
||
@render_widget.register(widgets.Textarea) # NOQA | ||
def _(widget, bound_field, template_name='viewflow/form/widgets/text_input.html', attrs=None): | ||
return render_widget_template(bound_field, template_name=template_name, attrs=attrs) | ||
|
||
@render_widget.register(widgets.Select) | ||
def _(widget, name, value, attrs=None): | ||
pass | ||
|
||
@render_widget.register(widgets.CheckboxInput) # NOQA | ||
def _(widget, bound_field, template_name='viewflow/form/widgets/text_input.html', attrs=None): | ||
return render_widget_template(bound_field, template_name=template_name, attrs=attrs) | ||
|
||
@render_widget.register(widgets.RadioSelect) | ||
def _(widget, name, value, attrs=None): | ||
pass | ||
|
||
@render_widget.register(widgets.Select) # NOQA | ||
def _(widget, bound_field, template_name='viewflow/form/widgets/text_input.html', attrs=None): | ||
return render_widget_template(bound_field, template_name=template_name, attrs=attrs) | ||
|
||
@render_widget.register(widgets.SelectMultiple) | ||
def _(widget, name, value, attrs=None): | ||
pass | ||
|
||
@render_widget.register(widgets.RadioSelect) # NOQA | ||
def _(widget, bound_field, template_name='viewflow/form/widgets/text_input.html', attrs=None): | ||
return render_widget_template(bound_field, template_name=template_name, attrs=attrs) | ||
|
||
|
||
@render_widget.register(widgets.SelectMultiple) # NOQA | ||
def _(widget, bound_field, template_name='viewflow/form/widgets/text_input.html', attrs=None): | ||
return render_widget_template(bound_field, template_name=template_name, attrs=attrs) |