<div id="autocompletePicker"></div>
new hx.AutocompletePicker('#autocompletePicker', ['a','b','c'])
<div id="autocompletePicker-async"></div>
function delayedItems (searchTerm, callback) {
setTimeout(function () {
callback(['a','b','c'])
}, 3000)
}
new hx.AutocompletePicker('#autocompletePicker-async', delayedItems)
<div>Tip: try searcing for 'Kent'</div>
<div id="autocompletePicker-externalMatch" type="text"></div>
const items = [{
name: 'Moorgate',
county: 'London'
}, {
name: 'Old Street',
county: 'London'
}, {
name: 'Canterbury',
county: 'Kent'
}, {
name: 'Dover',
county: 'Kent'
}]
function getItems (term, callback) {
if (term.length > 0) {
const a = []
const len = items.length
for (let i = 0; i < len; i++) {
const nameLc = items[i].name.toLowerCase()
const countyLc = items[i].county.toLowerCase()
const termLc = term.toLowerCase()
if (nameLc.indexOf(termLc) > -1 || countyLc.indexOf(termLc) > -1) {
a.push(items[i])
}
}
return callback(a)
} else {
return callback(items)
}
}
function renderer (elem, item) {
hx.select(elem)
.add(hx.detached('span').text(item.name))
.add(hx.label().text(item.county))
}
new hx.AutocompletePicker('#autocompletePicker-externalMatch', getItems, {
renderer: renderer,
matchType: 'external'
})
SingleSelect
component that merges Picker
and AutocompletePicker
functionality. [
"Bob",
"Steve"
]
valueLookup
must be provided in the options: const data = [
{
name "Bob",
age: 21
},
{
name: "Steve",
age: 25
}
]
const options = {
valueLookup: (item) => {
return item.name + ', ' + item.age
}
};
function data (term, callback) {
hx.json('path/to/data.json?search=' + term, (e, r) => {
callback(r.responseText)
})
}
matchType
to 'external': const options = {
matchType: 'external'
}
function getItems (term, cb) {
if (term.length > 0) {
const a = []
const len = items.length
for (let i = 0; i < len; i++) {
const { name, county }= items[i]
const nameLc = name.toLowerCase()
const countyLc = county.toLowerCase()
const termLc = term.toLowerCase()
if (nameLc.indexOf(termLc) > -1 || countyLc.indexOf(termLc) > -1) {
a.push(d)
}
}
return cb(a)
} else {
return cb(items)
}
}
hx-btn
class in addition to the value passed in here searchValues
option uses the passed in valueLookup to search on hx.filter
functions. All the filter types can be specified as the match type (e.g. 'startsWith', 'exact' or 'fuzzy') and the default value is 'contains' showOtherResults
option is enabled false
for non-static datasets or when using external matching data = [
{
name: 'Bob'
age: 12
},
...
]
valueLookup = function (item){
return item.name + ', ' + item.age;
}
[
"Bob",
"Steve"
]
valueLookup
must be provided in the options: const data = [
{
name "Bob",
age: 21
},
{
name: "Steve",
age: 25
}
]
const options = {
valueLookup: (item) => {
return item.name + ', ' + item.age
}
};
function data (term, callback) {
hx.json('path/to/data.json?search=' + term, (e, r) => {
callback(r.responseText)
})
}
matchType
to 'external': const options = {
matchType: 'external'
}
function getItems (term, cb) {
if (term.length > 0) {
const a = []
const len = items.length
for (let i = 0; i < len; i++) {
const { name, county }= items[i]
const nameLc = name.toLowerCase()
const countyLc = county.toLowerCase()
const termLc = term.toLowerCase()
if (nameLc.indexOf(termLc) > -1 || countyLc.indexOf(termLc) > -1) {
a.push(d)
}
}
return cb(a)
} else {
return cb(items)
}
}
autocompletePicker.value('Moorgate') // Value set to {name: 'Moorgate', county: 'London'}
autocompletePicker.value('London') // Value set to {name: 'Moorgate', county: 'London'}
autocompletePicker.value('Old') // Value set to {name: 'Old Street', county: 'London'}
autocompletePicker.value({name: 'Old Street', county: 'London'}) // Value set to {name: 'Old Street', county: 'London'}
autocompletePicker.value({name: 'Old Street'}) // Value set to {name: 'Old Street', county: 'London'}
autocompletePicker.value('Kent') // Value set to {name: 'Canterbury', county: 'Kent'}
SingleSelect
component that merges Picker
and AutocompletePicker
functionality. [
"Bob",
"Steve"
]
valueLookup
must be provided in the options: const data = [
{
name "Bob",
age: 21
},
{
name: "Steve",
age: 25
}
]
const options = {
valueLookup: (item) => {
return item.name + ', ' + item.age
}
};
function data (term, callback) {
hx.json('path/to/data.json?search=' + term, (e, r) => {
callback(r.responseText)
})
}
matchType
to 'external': const options = {
matchType: 'external'
}
function getItems (term, cb) {
if (term.length > 0) {
const a = []
const len = items.length
for (let i = 0; i < len; i++) {
const { name, county }= items[i]
const nameLc = name.toLowerCase()
const countyLc = county.toLowerCase()
const termLc = term.toLowerCase()
if (nameLc.indexOf(termLc) > -1 || countyLc.indexOf(termLc) > -1) {
a.push(d)
}
}
return cb(a)
} else {
return cb(items)
}
}
hx-btn
class in addition to the value passed in here searchValues
option uses the passed in valueLookup to search on hx.filter
functions. All the filter types can be specified as the match type (e.g. 'startsWith', 'exact' or 'fuzzy') and the default value is 'contains' showOtherResults
option is enabled false
for non-static datasets or when using external matching data = [
{
name: 'Bob'
age: 12
},
...
]
valueLookup = function (item){
return item.name + ', ' + item.age;
}