Skip to content

Commit

Permalink
fix editor no initial value bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
moeiniamir committed May 3, 2020
1 parent 5281320 commit 0e32093
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
14 changes: 10 additions & 4 deletions Pipfile.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified db.sqlite3
Binary file not shown.
6 changes: 1 addition & 5 deletions mhbank/forms.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
from django import forms
from django.utils.safestring import mark_safe


class MoratabEditor(forms.TextInput):
template_name = 'editor/index.html'
from .widgets import MoratabEditor


class QuestionForm(forms.ModelForm):
Expand Down
3 changes: 2 additions & 1 deletion mhbank/templates/editor/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@

<script type="text/javascript">
{#content = $('<textarea/>').html($('#moratab').html()).val();#}
content_{{ widget.name }} = "";
{% if widget.value != None %} content_{{ widget.name }} = "{{ widget.value|stringformat:'s' }}"{% endif %}
$("#hidden_markdown").val(content_{{ widget.name }});
$("#hidden_markdown_{{ widget.name }}").val(content_{{ widget.name }});
var editor_{{ widget.name }} = $('#moratab_{{ widget.name }}').moratab(content_{{ widget.name }},
{strings: {help: ''}},
(textContent) => {
Expand Down
16 changes: 3 additions & 13 deletions mhbank/widgets.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
from django.forms.widgets import Select
from django import forms


class DataAttributesSelect(Select):

def __init__(self, attrs=None, choices=(), data={}):
super(DataAttributesSelect, self).__init__(attrs, choices)
self.data = data

def create_option(self, name, value, label, selected, index, subindex=None, attrs=None): # noqa
option = super(DataAttributesSelect, self).create_option(name, value, label, selected, index, subindex=None, attrs=None) # noqa
# adds the data-attributes to the attrs context var
for data_attr, values in self.data.iteritems():
option['attrs'][data_attr] = values[option['value']]

return option
class MoratabEditor(forms.TextInput):
template_name = 'editor/index.html'

0 comments on commit 0e32093

Please sign in to comment.