[jifty-devel] Action autocomplete code diff
Edmund von der Burg
evdb at ecclestoad.co.uk
Fri Mar 23 13:50:04 EDT 2007
I was having trouble getting the autocomplete fields created is an
action using 'autocompleter is \&custom_code' working. The problem was
that no 'value' was ever being passed through to the 'custom_code'
sub.
By looking at the JSON string sent back to the server I found that the
value in the field was not being sent so I added a line to jifty.js.
Once the data was sent to the server I needed to do a bit of mucking
around to get it passed through to the action.
It seems strange that this should have been broken and not noticed. Am
I missing something?
The following diff fixes it for me. Sorry there are no tests - my
selenium skillz are not too hot :)
Cheers,
Edmund.
Index: share/web/static/js/jifty.js
===================================================================
--- share/web/static/js/jifty.js (revision 3047)
+++ share/web/static/js/jifty.js (working copy)
@@ -1008,8 +1008,12 @@
a['moniker'] = 'autocomplete';
a['class'] = 'Jifty::Action::Autocomplete';
a['fields'] = $H();
+
+ var field_name = Form.Element.getField(this.field);
a['fields']['moniker'] = this.action.moniker;
- a['fields']['argument'] = Form.Element.getField(this.field);
+ a['fields']['argument'] = field_name;
+ a['fields'][field_name] = Form.Element.getValue(this.field);
+
request['actions']['autocomplete'] = a;
request['actions'][this.action.moniker] = this.action.data_structure();
request['actions'][this.action.moniker]['active'] = 0;
Index: lib/Jifty/Action/Autocomplete.pm
===================================================================
--- lib/Jifty/Action/Autocomplete.pm (revision 3047)
+++ lib/Jifty/Action/Autocomplete.pm (working copy)
@@ -65,6 +65,10 @@
my $request_action = Jifty->web->request->action($moniker);
my $action = Jifty->web->new_action_from_request($request_action);
+ # Get the value that should be completed and save it to the action
+ my $value = $self->argument_value($argument);
+ $action->argument_value( $argument => $value);
+
my @completions = $action->_autocomplete_argument($argument);
$self->result->content->{completions} = \@completions;
More information about the jifty-devel
mailing list