Problem with ajax search. I am added listener search and run function ajax get data by search item.
In time of running function: dropped focus and disable input. Its problem, how to fix ?
var myHeaders = new Headers()
this.choices_example.passedElement.element.addEventListener('search', (event) => {
if (event.detail.value.length > 2) {
const formData = new FormData()
formData.append('find', event.detail.value)
this.choices_example.ajax(function (callback) {
fetch('some-url', {
method: 'POST',
headers: myHeaders,
cache: 'default',
body: formData
}).then(function (response) {
response.json().then(function (data) {
console.log(data)
callback(data, 'key', 'value')
})
}).catch(function (error) {
console.error(error)
})
})
}
})
setChoices() fixed my problem
@shmidtelson considering similar, can you provide more detail or code example of how/where you used setChoices to resolve your problem?
Most helpful comment
@shmidtelson considering similar, can you provide more detail or code example of how/where you used
setChoicesto resolve your problem?