So basically i have a simple collection with only one column, a connected table, a text input and a connected submit button to add new items on a page (in theory).
The user input filters the table as you type and the table shows everything as its supposed to.
The add button is disabled if the filter matches anything in the collection and enabled if not.
If I connect the TextInput to the collection its disabled and unusable in preview and live.
Not sure what i have to change to get it working as it is supposed to.
EDIT: I connected the collection 2 times now, one as read-only and one as write-only (Before it was one with read and write). The TextInput and button connects to the write-only and now everything is working fine. Beside table not updating after a submit but thats easy.
I will keep this post incase someone has the same problem or anyone can explain me what i did wrong with the read-write database.
This is my code:
import wixData from ‘wix-data’;
$w.onReady(function () {
$w(‘#addClanButton’).disable();
$w(‘#search’).onKeyPress((eventHandler) => {
let key = eventHandler.key;
let input;
if (key === ‘Backspace’) {
input = $w(‘#search’).value.slice(0, $w(‘#search’).value.length-1);
} else if(key.length === 1) {
input = $w(‘#search’).value + key;
}
console.log(input);
update_table(input);
update_addButton();
});
});
function update_table(input) {
$w(‘#clans’).setFilter(wixData.filter().contains(‘clan’, input))
.catch((error) => {
let errorMsg = error.message;
let code = error.code;
});
}
function update_addButton() {
if ($w(‘#clans’).getTotalCount() === 0) {
$w(‘#addClanButton’).enable();
} else {
$w(‘#addClanButton’).disable();
}
}