Hi Jesse,
My code involves RDBMS connection and is a bit complicated to clean up right now.
But I think I was able to reproduce the problem I'm facing by lightly modifiying the nitrogen example demo.
Below, I just modifed the {value, <<"Elixir é"/utf8>> } entry to add an european letter.
When selecting this entry in the list I get the error with undefined.
Hope this helps,
Cheers,
Sébastien.
%% -*- coding: utf-8 -*-
-module (autocomplete).
-include_lib ("nitrogen_core/include/wf.hrl").
-compile(export_all).
main() -> #template{file="./site/templates/carte.html"}.
description() -> "description".
title() -> "Autocompletion".
body() -> w_panel:get_body_panel(?MODULE).
main_div_body() ->
[
"<p>
The <code>#textbox_autocomplete{}</code> element gives you a simple way
to add autocompletion with options to a textbox element. It relies on
JSON encoding, and expects your application to have two functions
exported: <code>autocomplete_enter_event(SearchTerm, Tag)</code>, which
is called as the user types and
<code>autocomplete_select_event(SelectedElement, Tag)</code>, which is
called when the user selects and element from the list.
",
#p{},
#label { text="What's your favorite programming language?" },
#textbox_autocomplete { tag=auto1, minLength=1 },
#flash {}
].
does_search_match(LangRec, SearchTerm0) ->
%% We extract the label from the passed Lang "Rec" (which is just a proplist)
Label0 = proplists:get_value(label, LangRec),
%% And convert it ot lower case
Label = string:to_lower(wf:to_list(Label0)),
%% and also convert the SearchTerm to lowercase
SearchTerm = string:to_lower(SearchTerm0),
%% Then see if SearchTerm is contained anywhere in the Label
string:str(Label, SearchTerm) > 0.
autocomplete_enter_event(SearchTerm, _Tag) ->
Data0 = base_data(),
%% Let's filter the list based on the SearchTerm
Data = [LangRec || LangRec <- Data0, does_search_match(LangRec, SearchTerm)],
%% Encode the Data into json for the autocomplete event. As you can see
%% from the base_data function below, it expects each record to have an
%% "id", a "label", and a "value". "id" is a short-hand identifier. "label"
%% is what will be displayed in the dropdown, and "value" will be passed
%% along with the "id", then decoded from json and sent to the
%% autocomplete_select_event function as a proplist.
wf:json_encode(Data).
autocomplete_select_event(SelectedElement, _Tag) ->
%% SelectedElement is a proplist
%% Let's tell the user what we selected!
wf:flash(proplists:get_value(<<"value">>, SelectedElement)),
ok.
base_data() ->
[
[{id, <<"c">>}, {label, <<"C">>}, {value, <<"C">>}],
[{id, <<"cpp">>}, {label, <<"C++">>}, {value, <<"C++">>}],
[{id, <<"clojure">>}, {label, <<"Clojure">>}, {value, <<"Clojure">>}],
[{id, <<"coffeescript">>}, {label, <<"Coffeescript">>} , {value, <<"Coffeescript">> }],
[{id, <<"elixir">>}, {label, <<"Elixir">>} , {value, <<"Elixir é"/utf8>> }],
[{id, <<"erlang">>}, {label, <<"Erlang">>} , {value, <<"Erlang">> }],
[{id, <<"go">>}, {label, <<"Golang">>} , {value, <<"Golang">> }],
[{id, <<"haskell">>}, {label, <<"Haskell">>} , {value, <<"Haskell">> }],
[{id, <<"lua">>}, {label, <<"Lua">>} , {value, <<"Lua">> }],
[{id, <<"java">>}, {label, <<"Java">>} , {value, <<"Java">> }],
[{id, <<"js">>}, {label, <<"Javascript">>} , {value, <<"Javascript">> }],
[{id, <<"perl">>}, {label, <<"Perl">>} , {value, <<"Perl">> }],
[{id, <<"php">>}, {label, <<"PHP">>} , {value, <<"PHP">> }],
[{id, <<"python">>}, {label, <<"Python">>}, {value, <<"Python">>}],
[{id, <<"objc">>}, {label, <<"Objective-C">>} , {value, <<"Objective-C">> }],
[{id, <<"ocaml">>}, {label, <<"OCaml">>} , {value, <<"OCaml">> }],
[{id, <<"ruby">>}, {label, <<"Ruby">>} , {value, <<"Ruby">> }],
[{id, <<"scala">>}, {label, <<"Scala">>} , {value, <<"Scala">> }],
[{id, <<"swift">>}, {label, <<"Swift">>} , {value, <<"Swift">> }]
].