mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-12-26 08:53:46 +00:00
Gestion des hidden fields
This commit is contained in:
parent
c4bdab82f0
commit
111527b53b
1 changed files with 16 additions and 12 deletions
|
@ -62,11 +62,13 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
||||||
t_fields = typeahead_fields.split(',')
|
t_fields = typeahead_fields.split(',')
|
||||||
exclude = kwargs.get('exclude', None)
|
exclude = kwargs.get('exclude', None)
|
||||||
exclude = exclude.split(',') if exclude else []
|
exclude = exclude.split(',') if exclude else []
|
||||||
|
hidden = [h.name for h in django_form.hidden_fields()]
|
||||||
|
|
||||||
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 :
|
||||||
|
if not f_name in hidden :
|
||||||
form += render_tag(
|
form += render_tag(
|
||||||
'div',
|
'div',
|
||||||
attrs = {'class': 'form-group'},
|
attrs = {'class': 'form-group'},
|
||||||
|
@ -75,7 +77,8 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
||||||
hidden_tag( f_name ) +
|
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,14 +92,15 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
|
||||||
def input_id( f_name ):
|
def input_id( f_name ):
|
||||||
return 'typeahead_input_'+f_name
|
return 'typeahead_input_'+f_name
|
||||||
|
|
||||||
def select_id( f_name ):
|
def hidden_id( f_name ):
|
||||||
return 'typeahead_select_'+f_name
|
return 'typeahead_select_'+f_name
|
||||||
|
|
||||||
def hidden_tag( f_name ):
|
def hidden_tag( f_name ):
|
||||||
return render_tag(
|
return render_tag(
|
||||||
'input',
|
'input',
|
||||||
attrs={
|
attrs={
|
||||||
'id': select_id(f_name),
|
'id': hidden_id(f_name),
|
||||||
|
'maxlength': 255,
|
||||||
'name': f_name,
|
'name': f_name,
|
||||||
'type': 'hidden',
|
'type': 'hidden',
|
||||||
'value': ''
|
'value': ''
|
||||||
|
@ -173,7 +177,7 @@ def typeahead_datasets( f_name ) :
|
||||||
|
|
||||||
def typeahead_updater( f_name ):
|
def typeahead_updater( f_name ):
|
||||||
return 'function(evt, item) { ' \
|
return 'function(evt, item) { ' \
|
||||||
'$("#'+select_id(f_name)+'").val( item.key ); ' \
|
'$("#'+hidden_id(f_name)+'").val( item.key ); ' \
|
||||||
'return item; ' \
|
'return item; ' \
|
||||||
'}'
|
'}'
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue