mirror of
https://gitlab2.federez.net/re2o/re2o
synced 2024-11-24 04:13:12 +00:00
Utilise l'id des objets plutôt que leur nom pour les id HTML
This commit is contained in:
parent
1083f8d199
commit
e51b484731
1 changed files with 46 additions and 16 deletions
|
@ -296,8 +296,8 @@ def mbf_js( f_name, f_value, f_bound, multiple,
|
||||||
input_id = input_id( f_bound ),
|
input_id = input_id( f_bound ),
|
||||||
datasets = default_datasets( f_name, match_func ),
|
datasets = default_datasets( f_name, match_func ),
|
||||||
create = tokenfield_create( f_name, f_bound ),
|
create = tokenfield_create( f_name, f_bound ),
|
||||||
edit = tokenfield_edit( f_bound ),
|
edit = tokenfield_edit( f_name, f_bound ),
|
||||||
remove = tokenfield_remove( f_bound ),
|
remove = tokenfield_remove( f_name, f_bound ),
|
||||||
updates = ''.join( [ (
|
updates = ''.join( [ (
|
||||||
'$( "#{u_id}" ).change( function() {{'
|
'$( "#{u_id}" ).change( function() {{'
|
||||||
'setup_{f_name}();'
|
'setup_{f_name}();'
|
||||||
|
@ -495,6 +495,8 @@ def tokenfield_create( f_name, f_bound ):
|
||||||
""" The JS script triggered when a new token is created in tokenfield. """
|
""" The JS script triggered when a new token is created in tokenfield. """
|
||||||
return (
|
return (
|
||||||
'function(evt) {{'
|
'function(evt) {{'
|
||||||
|
'var k = evt.attrs.key;'
|
||||||
|
'if (!k) {{'
|
||||||
'var data = evt.attrs.value;'
|
'var data = evt.attrs.value;'
|
||||||
'var i = 0;'
|
'var i = 0;'
|
||||||
'while ( i<choices_{f_name}.length &&'
|
'while ( i<choices_{f_name}.length &&'
|
||||||
|
@ -502,10 +504,12 @@ def tokenfield_create( f_name, f_bound ):
|
||||||
'i++;'
|
'i++;'
|
||||||
'}}'
|
'}}'
|
||||||
'if ( i === choices_{f_name}.length ) {{ return false; }}'
|
'if ( i === choices_{f_name}.length ) {{ return false; }}'
|
||||||
|
'k = choices_{f_name}[i].key;'
|
||||||
|
'}}'
|
||||||
'var new_input = document.createElement("input");'
|
'var new_input = document.createElement("input");'
|
||||||
'new_input.type = "hidden";'
|
'new_input.type = "hidden";'
|
||||||
'new_input.id = "{hidden_id}_"+data;'
|
'new_input.id = "{hidden_id}_"+k.toString();'
|
||||||
'new_input.value = choices_{f_name}[i].key.toString();'
|
'new_input.value = k.toString();'
|
||||||
'new_input.name = "{name}";'
|
'new_input.name = "{name}";'
|
||||||
'$( "#{div_id}" ).append(new_input);'
|
'$( "#{div_id}" ).append(new_input);'
|
||||||
'}}'
|
'}}'
|
||||||
|
@ -516,27 +520,53 @@ def tokenfield_create( f_name, f_bound ):
|
||||||
div_id = custom_div_id( f_bound )
|
div_id = custom_div_id( f_bound )
|
||||||
)
|
)
|
||||||
|
|
||||||
def tokenfield_edit( f_bound ):
|
def tokenfield_edit( f_name, f_bound ):
|
||||||
""" The JS script triggered when a token is edited in tokenfield. """
|
""" The JS script triggered when a token is edited in tokenfield. """
|
||||||
return (
|
return (
|
||||||
'function(evt) {{'
|
'function(evt) {{'
|
||||||
|
'var k = evt.attrs.key;'
|
||||||
|
'if (!k) {{'
|
||||||
'var data = evt.attrs.value;'
|
'var data = evt.attrs.value;'
|
||||||
'var old_input = document.getElementById( "{hidden_id}_"+data );'
|
'var i = 0;'
|
||||||
|
'while ( i<choices_{f_name}.length &&'
|
||||||
|
'choices_{f_name}[i].value !== data ) {{'
|
||||||
|
'i++;'
|
||||||
|
'}}'
|
||||||
|
'if ( i === choices_{f_name}.length ) {{ return true; }}'
|
||||||
|
'k = choices_{f_name}[i].key;'
|
||||||
|
'}}'
|
||||||
|
'var old_input = document.getElementById('
|
||||||
|
'"{hidden_id}_"+k.toString()'
|
||||||
|
');'
|
||||||
'old_input.parentNode.removeChild(old_input);'
|
'old_input.parentNode.removeChild(old_input);'
|
||||||
'}}'
|
'}}'
|
||||||
).format(
|
).format(
|
||||||
|
f_name = f_name,
|
||||||
hidden_id = hidden_id( f_bound )
|
hidden_id = hidden_id( f_bound )
|
||||||
)
|
)
|
||||||
|
|
||||||
def tokenfield_remove( f_bound ):
|
def tokenfield_remove( f_name, f_bound ):
|
||||||
""" The JS script trigggered when a token is removed from tokenfield. """
|
""" The JS script trigggered when a token is removed from tokenfield. """
|
||||||
return (
|
return (
|
||||||
'function(evt) {{'
|
'function(evt) {{'
|
||||||
|
'var k = evt.attrs.key;'
|
||||||
|
'if (!k) {{'
|
||||||
'var data = evt.attrs.value;'
|
'var data = evt.attrs.value;'
|
||||||
'var old_input = document.getElementById( "{hidden_id}_"+data );'
|
'var i = 0;'
|
||||||
|
'while ( i<choices_{f_name}.length &&'
|
||||||
|
'choices_{f_name}[i].value !== data ) {{'
|
||||||
|
'i++;'
|
||||||
|
'}}'
|
||||||
|
'if ( i === choices_{f_name}.length ) {{ return true; }}'
|
||||||
|
'k = choices_{f_name}[i].key;'
|
||||||
|
'}}'
|
||||||
|
'var old_input = document.getElementById('
|
||||||
|
'"{hidden_id}_"+k.toString()'
|
||||||
|
');'
|
||||||
'old_input.parentNode.removeChild(old_input);'
|
'old_input.parentNode.removeChild(old_input);'
|
||||||
'}}'
|
'}}'
|
||||||
).format(
|
).format(
|
||||||
|
f_name = f_name,
|
||||||
hidden_id = hidden_id( f_bound )
|
hidden_id = hidden_id( f_bound )
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue