Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from eldarion/multiple-text-field
Improve output of MultipleTextField widget
- Loading branch information
Showing
5 changed files
with
41 additions
and
27 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
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,23 +0,0 @@ | ||
import json | ||
from django import forms | ||
|
||
|
||
class MultipleTextField(forms.MultiValueField): | ||
def __init__(self, fields_length, **kwargs): | ||
fields = tuple(forms.CharField(max_length=200) for _ in range(fields_length)) | ||
kwargs.update({"fields": fields}) | ||
super(MultipleTextField, self).__init__(**kwargs) | ||
self.fields_length = fields_length | ||
|
||
def compress(self, data_list): | ||
return json.dumps(data_list) | ||
|
||
|
||
class MultiTextWidget(forms.MultiWidget): | ||
def __init__(self, widgets_length, **kwargs): | ||
widgets = (forms.TextInput() for _ in range(widgets_length)) | ||
kwargs.update({"widgets": widgets}) | ||
super(MultiTextWidget, self).__init__(**kwargs) | ||
|
||
def decompress(self, value): | ||
return json.loads(value) if value is not None else [] | ||
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
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,5 @@ | ||
<ol> | ||
{% for input in inputs %} | ||
<li class="form-inline full-width">{{ input }}</li> | ||
{% endfor %} | ||
</ol> |