I try to use some of my jQuery plugins within Alpine (of course Alpine should replace jQuery in long-term). This autocomplete plugin theoretically works as expected, but I can't set the targetCustomerId from within the onSelect(). How can I access and change the values of my object properties from inside the autocomplete functions?
x-data="
postForm($el.id, 'contracts/add', {
targetCustomerId: '<?=$customer->CUSTOMERID;?>',
init() {
customerInput = $($refs.autocompleteInput).autocomplete({
type: 'POST',
serviceUrl: 'api/getCustomers',
onSearchStart: function() {
$(this).addClass('input-loader')
},
onSearchComplete: function() {
$(this).removeClass('input-loader')
},
onSearchError: function() {
$(this).removeClass('input-loader')
},
onSelect: function (suggestion) {
this.targetCustomerId = suggestion.value;
}
});
}
})
"
The postForm() is simplified just something like this:
function postForm(formId, url, objSettings) {
var defaults = {
form: document.getElementById(formId),
formData: '',
message: '',
isLoading: false
}
return {...defaults, ...objSettings};
}
postFormfunction and some form code? Do you try to usetargetCustomerIdas an Alpine.js variable?