Hi,
-I have 5 x #input
-I am trying to disable #input1 after field is full and already written in database.
In exchange #input<2 to 5> active and available to input and submit.
- Disables every field which is written and only allows empty fields to be filled.
I already got something but stuck at this point, something is wrong.
import wixData from 'wix-data';
$w.onReady(function () {
wixData.query("dataset2")
.eq('points1', value.points1)
.find()
.then((results) => {
if (results.items.length) {
$w('#input1').disable();
} else {
$w('#input1').enabled();
}
});
.eq('points2', value.points2)
.find()
.then((results) => {
if (results.items.length) {
$w('#input2').disable();
} else {
$w('#input2').enabled();
}
});
});
Can someone guide me what is wrong here and how it should look?
Or at least for one input only.
Thank you
@Ahmad @Yisrael (Wix)
I am trying this way also:
$w.onReady(() => { $w("#dynamicDataset").onReady(() => { if ($w("#fish1").value === null ) { $w("#fish1").enable(); } else { $w("#fish1").disable(); } }); });
Gives me action only always disabled.
@Ahmad @Ajit Kumar
Hi, Thanks for answer.
Both codes are not working. "value is not defined" error.
@Ahmad @Ajit Kumar
Hi there ..
Is "dataset2" your database/collection name? If it's not, then you need to replace it with your collection name, also, you're copying a portion of the query (which is inactive) and does nothing, what I suggest is to include the if statement of the second portion inside the first one.
import wixData from 'wix-data'; $w.onReady(function () { wixData.query("dataset2").eq('points1', value.points1).find().then((result) => { // Check to see if you have a matching result if (result.length > 0) { let item = result.items[0]; /* Check to see if fields are empty or not, fill the existing ones and disable them */ // Check the if the first name exist, and fill it if necessary if (item.firstName) { $w('#firstName').value = item.firstName; $w('#firstName').readOnly = true; } } })
Hope this helps~!
Ahmad
You have much errors in your code. But no.problem !!!!!!
1st error - wixData.query("dataset2")
Here instead of "dataset2" you need to provide the Database name....
2nd error - if (results.items.length) {
Here try this ->
if (results.items.length > 0) {
3rd error - } else { $w('#input1').enabled(); }
Try this ->
$w('#input1').enable();
4th error - .eq('points2', value.points2)
Try this -
wixData.query("DatabaseName")
.eq('points2', value.points2)
5th and 6th error ->
if (results.items.length) { $w('#input2').disable(); } else { $w('#input2').enabled(); }
Instead try this ->
if (results.items.length > 0) { $w('#input2').disable(); } else { $w('#input2').enable(); }