Skip to content

Commit fac0676

Browse files
briandipalmaLeaVerou
authored andcommitted
docs: Explain how to insert label into input
1 parent 8df26d8 commit fac0676

1 file changed

Lines changed: 16 additions & 2 deletions

File tree

index.html

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ <h1>Basic usage</h1>
125125

126126
awesomplete.list = ["Ada", "Java", "JavaScript", "Brainfuck", "LOLCODE", "Node.js", "Ruby on Rails"];</code></pre>
127127

128-
<p>Suggestions with different <strong>label</strong> and <strong>value</strong> are supported too. The label will be shown in autocompleter and the value will be inserted into the input.</p>
128+
<p>Suggestions with different <strong>label</strong> and <strong>value</strong> are supported too. The label will be shown in autocompleter and the <strong>value</strong> will be inserted into the input. If you want to insert the label into the input you can provide your own <strong>replace</strong> function</p>
129129

130130
<pre class="language-markup"><code>&lt;input id="myinput" /></code></pre>
131131
<pre class="language-javascript"><code>var input = document.getElementById("myinput");
@@ -146,7 +146,21 @@ <h1>Basic usage</h1>
146146
[ "China", "CN" ],
147147
[ "United States", "US" ]
148148
]
149-
});</code></pre>
149+
});
150+
151+
// Show label and insert label into the input:
152+
new Awesomplete(input, {
153+
list: [
154+
{ label: "Belarus", value: "BY" },
155+
{ label: "China", value: "CN" },
156+
{ label: "United States", value: "US" }
157+
],
158+
// insert label instead of value into the input.
159+
replace: function(suggestion) {
160+
this.input.value = suggestion.label;
161+
}
162+
});
163+
</code></pre>
150164

151165
</section>
152166

0 commit comments

Comments
 (0)