Another pass on search+select for autocomplete that handles user input much better.

This commit is contained in:
Jeremy Goecks
2010-05-21 15:50:49 -04:00
parent ab53cc6d3b
commit dc0e679767
3 changed files with 39 additions and 33 deletions
+1 -1
View File
@@ -44,7 +44,7 @@ def js( *args ):
TODO: This has a hardcoded "?v=2" to defeat caching. This should be done
in a better way.
"""
return "\n".join( [ javascript_include_tag( "/static/scripts/" + name + ".js?v=2" ) for name in args ] )
return "\n".join( [ javascript_include_tag( "/static/scripts/" + name + ".js?v=3" ) for name in args ] )
# Hashes
+37 -31
View File
@@ -242,44 +242,50 @@ function replace_big_select_inputs(min_length) {
// Get refresh vals.
var refresh_vals = select_elt.attr('refresh_on_change_values');
if (refresh_vals !== undefined)
refresh_vals = refresh_vals.split(",")
text_input_elt.keyup( function( e )
refresh_vals = refresh_vals.split(",");
// Function that attempts to refresh based on the value in the text element.
var try_refresh_fn = function()
{
if ( ( e.keyCode == 13 ) && // Return Key
( return_key_pressed_for_autocomplete == true ) ) // Make sure return key was for autocomplete.
//
// If value entered can be matched to value, do so and refresh by submitting parent form.
//
// Get new value and see if it can be matched.
var cur_value = text_input_elt.attr('value');
var new_value = select_mapping[cur_value];
if (new_value !== null && new_value !== undefined)
{
//
// If value entered can be matched to value, do so and refresh by submitting parent form.
//
// Get new value and see if it can be matched.
var cur_value = text_input_elt.attr('value');
var new_value = select_mapping[cur_value];
if (new_value !== null && new_value !== undefined)
// Do refresh if new value is refresh value or if there are no refresh values.
refresh = false;
if (refresh_vals !== undefined)
{
// Do refresh if new value is refresh value or if there are no refresh values.
refresh = false;
if (refresh_vals !== undefined)
{
for (var i= 0; i < refresh_vals.length; i++ )
if (new_value == refresh_vals[i])
{
refresh = true;
break;
}
}
else
// Refresh for all values.
refresh = true;
for (var i= 0; i < refresh_vals.length; i++ )
if (new_value == refresh_vals[i])
{
refresh = true;
break;
}
}
else
// Refresh for all values.
refresh = true;
if (refresh)
{
text_input_elt.attr('value', new_value);
text_input_elt.parents('form').submit();
}
if (refresh)
{
text_input_elt.attr('value', new_value);
text_input_elt.parents('form').submit();
}
}
};
// Attempt refresh if (a) result event fired by autocomplete (indicating autocomplete occurred) or (b) on keyup (in which
// case a user may have manually entered a value that needs to be refreshed).
text_input_elt.bind("result", try_refresh_fn);
text_input_elt.keyup( function(e) {
try_refresh_fn();
});
}
});
}
File diff suppressed because one or more lines are too long