mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-25 16:33:47 +00:00
Laisse bootstrap_form faire les rendu au maximum
This commit is contained in:
parent
ba1f55adf7
commit
883258d079
1 changed files with 17 additions and 32 deletions
|
@ -20,6 +20,7 @@
|
||||||
|
|
||||||
from django import template
|
from django import template
|
||||||
from django.utils.safestring import mark_safe
|
from django.utils.safestring import mark_safe
|
||||||
|
from django.forms import TextInput
|
||||||
from bootstrap3.templatetags.bootstrap3 import bootstrap_form
|
from bootstrap3.templatetags.bootstrap3 import bootstrap_form
|
||||||
from bootstrap3.utils import render_tag
|
from bootstrap3.utils import render_tag
|
||||||
from bootstrap3.forms import render_field
|
from bootstrap3.forms import render_field
|
||||||
|
@ -67,18 +68,24 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
||||||
form = ''
|
form = ''
|
||||||
for f_name, f_value in django_form.fields.items() :
|
for f_name, f_value in django_form.fields.items() :
|
||||||
if not f_name in exclude :
|
if not f_name in exclude :
|
||||||
if f_name in t_fields :
|
if f_name in t_fields and not f_name in hidden :
|
||||||
if not f_name in hidden :
|
f_bound = f_value.get_bound_field( django_form, f_name )
|
||||||
|
f_value.widget = TextInput(
|
||||||
|
attrs={
|
||||||
|
'name': 'typeahead_'+f_name,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
form += render_field(
|
||||||
|
f_value.get_bound_field( django_form, f_name ),
|
||||||
|
*args,
|
||||||
|
**kwargs
|
||||||
|
)
|
||||||
form += render_tag(
|
form += render_tag(
|
||||||
'div',
|
'div',
|
||||||
attrs = {'class': 'form-group'},
|
attrs = {'class': 'form-group'},
|
||||||
content = label_tag( f_name, f_value ) +
|
content = hidden_tag( f_bound, f_name ) +
|
||||||
input_tag( f_name, f_value ) +
|
|
||||||
hidden_tag( f_name ) +
|
|
||||||
typeahead_full_script( f_name, f_value )
|
typeahead_full_script( f_name, f_value )
|
||||||
)
|
)
|
||||||
else:
|
|
||||||
form += hidden_tag( f_name )
|
|
||||||
else:
|
else:
|
||||||
form += render_field(
|
form += render_field(
|
||||||
f_value.get_bound_field(django_form, f_name),
|
f_value.get_bound_field(django_form, f_name),
|
||||||
|
@ -89,45 +96,23 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
||||||
|
|
||||||
return mark_safe( form )
|
return mark_safe( form )
|
||||||
|
|
||||||
def input_id( f_name ):
|
def input_id( f_name ) :
|
||||||
return 'typeahead_input_'+f_name
|
return 'id_'+f_name
|
||||||
|
|
||||||
def hidden_id( f_name ):
|
def hidden_id( f_name ):
|
||||||
return 'typeahead_select_'+f_name
|
return 'typeahead_hidden_'+f_name
|
||||||
|
|
||||||
def hidden_tag( f_name ):
|
def hidden_tag( f_name ):
|
||||||
return render_tag(
|
return render_tag(
|
||||||
'input',
|
'input',
|
||||||
attrs={
|
attrs={
|
||||||
'id': hidden_id(f_name),
|
'id': hidden_id(f_name),
|
||||||
'maxlength': 255,
|
|
||||||
'name': f_name,
|
'name': f_name,
|
||||||
'type': 'hidden',
|
'type': 'hidden',
|
||||||
'value': ''
|
'value': ''
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
def label_tag( f_name, f_value ):
|
|
||||||
return render_tag(
|
|
||||||
'label',
|
|
||||||
attrs={
|
|
||||||
'class': 'control-label',
|
|
||||||
'for': input_id(f_name)
|
|
||||||
},
|
|
||||||
content=f_value.label
|
|
||||||
)
|
|
||||||
|
|
||||||
def input_tag( f_name, f_value ):
|
|
||||||
return render_tag(
|
|
||||||
'input',
|
|
||||||
attrs={
|
|
||||||
'class': 'form-control',
|
|
||||||
'id': input_id(f_name),
|
|
||||||
'type': 'text',
|
|
||||||
'placeholder': f_value.empty_label
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
def typeahead_full_script( f_name, f_value ) :
|
def typeahead_full_script( f_name, f_value ) :
|
||||||
js_content = \
|
js_content = \
|
||||||
'$("#'+input_id(f_name)+'").ready( function() {\n' + \
|
'$("#'+input_id(f_name)+'").ready( function() {\n' + \
|
||||||
|
|
Loading…
Reference in a new issue