mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-30 08:32:26 +00:00
Fix: BFT Tag : JS fail sur le reset des input quand init_val != ""
Ajoute une fonction init_input qui fait ce que faisait reset_input avant et maintenant reset_input, se contente de mettre "" dans les input
This commit is contained in:
parent
d21e39ee88
commit
d52e4d58e2
1 changed files with 28 additions and 10 deletions
|
@ -232,37 +232,45 @@ def typeahead_js( f_name, f_value, f_bound,
|
||||||
|
|
||||||
js_content = (
|
js_content = (
|
||||||
'var choices_{f_name} = {choices};'
|
'var choices_{f_name} = {choices};'
|
||||||
|
'var engine_{f_name};'
|
||||||
'var setup_{f_name} = function() {{'
|
'var setup_{f_name} = function() {{'
|
||||||
'var engine_{f_name} = {engine};'
|
'engine_{f_name} = {engine};'
|
||||||
'$( "#{input_id}" ).typeahead( "destroy" );'
|
'$( "#{input_id}" ).typeahead( "destroy" );'
|
||||||
'$( "#{input_id}" ).typeahead( {datasets} );'
|
'$( "#{input_id}" ).typeahead( {datasets} );'
|
||||||
'{reset_input}'
|
|
||||||
'}};'
|
'}};'
|
||||||
'$( "#{input_id}" ).bind( "typeahead:select", {updater} );'
|
'$( "#{input_id}" ).bind( "typeahead:select", {updater} );'
|
||||||
'$( "#{input_id}" ).bind( "typeahead:change", {change} );'
|
'$( "#{input_id}" ).bind( "typeahead:change", {change} );'
|
||||||
'{updates}'
|
'{updates}'
|
||||||
'$( "#{input_id}" ).ready( setup_{f_name} );'
|
'$( "#{input_id}" ).ready( function() {{'
|
||||||
|
'setup_{f_name}();'
|
||||||
|
'{init_input}'
|
||||||
|
'}} );'
|
||||||
).format(
|
).format(
|
||||||
f_name = f_name,
|
f_name = f_name,
|
||||||
choices = choices,
|
choices = choices,
|
||||||
engine = engine,
|
engine = engine,
|
||||||
input_id = input_id( f_name ),
|
input_id = input_id( f_name ),
|
||||||
datasets = default_datasets( f_name, match_func ),
|
datasets = default_datasets( f_name, match_func ),
|
||||||
reset_input = reset_input( f_name, f_bound ),
|
|
||||||
updater = typeahead_updater( f_name ),
|
updater = typeahead_updater( f_name ),
|
||||||
change = typeahead_change( f_name ),
|
change = typeahead_change( f_name ),
|
||||||
updates = ''.join(
|
updates = ''.join( [ (
|
||||||
['$( "#{u_id}").change( setup_{f_name} );'.format(
|
'$( "#{u_id}" ).change( function() {{'
|
||||||
|
'setup_{f_name}();'
|
||||||
|
'{reset_input}'
|
||||||
|
'}} );'
|
||||||
|
).format(
|
||||||
u_id = u_id,
|
u_id = u_id,
|
||||||
|
reset_input = reset_input( f_name ),
|
||||||
f_name = f_name
|
f_name = f_name
|
||||||
) for u_id in update_on ]
|
) for u_id in update_on ]
|
||||||
)
|
),
|
||||||
|
init_input = init_input( f_name, f_bound ),
|
||||||
)
|
)
|
||||||
|
|
||||||
return render_tag( 'script', content=mark_safe( js_content ) )
|
return render_tag( 'script', content=mark_safe( js_content ) )
|
||||||
|
|
||||||
def reset_input( f_name, f_bound ) :
|
def init_input( f_name, f_bound ) :
|
||||||
""" The JS script to reset the fields values """
|
""" The JS script to init the fields values """
|
||||||
init_key = f_bound.value() or '""'
|
init_key = f_bound.value() or '""'
|
||||||
return (
|
return (
|
||||||
'$( "#{input_id}" ).typeahead("val", {init_val});'
|
'$( "#{input_id}" ).typeahead("val", {init_val});'
|
||||||
|
@ -278,6 +286,16 @@ def reset_input( f_name, f_bound ) :
|
||||||
hidden_id = hidden_id( f_name )
|
hidden_id = hidden_id( f_name )
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def reset_input( f_name ) :
|
||||||
|
""" The JS script to reset the fields values """
|
||||||
|
return (
|
||||||
|
'$( "#{input_id}" ).typeahead("val", "");'
|
||||||
|
'$( "#{hidden_id}" ).val( "" );'
|
||||||
|
).format(
|
||||||
|
input_id = input_id( f_name ),
|
||||||
|
hidden_id = hidden_id( f_name )
|
||||||
|
)
|
||||||
|
|
||||||
def default_choices( f_value ) :
|
def default_choices( f_value ) :
|
||||||
""" The JS script creating the variable choices_<fieldname> """
|
""" The JS script creating the variable choices_<fieldname> """
|
||||||
return '[ {objects} ]'.format(
|
return '[ {objects} ]'.format(
|
||||||
|
|
Loading…
Reference in a new issue