8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-28 01:43:46 +00:00

Empty label dans le placeholder + bind (''->empty value)

This commit is contained in:
Maël Kervella 2017-10-06 00:50:13 +00:00
parent e5bdff792b
commit 0cb784fcf1

View file

@ -73,6 +73,7 @@ def bootstrap_form_typeahead(django_form, typeahead_fields, *args, **kwargs):
f_value.widget = TextInput(
attrs={
'name': 'typeahead_'+f_name,
'placeholder': f_value.empty_label
}
)
form += render_field(
@ -124,13 +125,16 @@ def typeahead_full_script( f_name, f_value ) :
').bind(\n' + \
'"typeahead:select", ' + \
typeahead_updater( f_name ) + '\n' + \
').bind(\n' + \
'"typeahead:change", ' + \
typeahead_change( f_name ) + '\n' + \
')\n' + \
'});\n'
return render_tag( 'script', content=mark_safe( js_content ) )
def reset_input( f_name, f_value ) :
return '$("#'+input_id(f_name)+'").val("'+f_value.empty_label+'");'
return '$("#'+input_id(f_name)+'").val("");'
def typeahead_choices( f_value ) :
return 'var choices = [' + \
@ -179,5 +183,11 @@ def typeahead_updater( f_name ):
return 'function(evt, item) { ' \
'$("#'+hidden_id(f_name)+'").val( item.key ); ' \
'return item; ' \
'}'
'}'
def typeahead_change( f_name ):
return 'function(evt) { ' \
'if (evt.currentTarget.value === "") {' \
'$("#'+hidden_id(f_name)+'").val(""); ' \
'}' \
'}'