Hello Everyone,
I am having an issue trying to figure out how to collapse multiple textbox when there is no data provided via the dataset. I have approached this different ways and none have been successful (other than turning off all the textboxes).
Here is my current code:
// For full API documentation, including code examples, visit http://wix.to/94BuAAs
import wixData from 'wix-data';
$w.onReady(function () {
//Wait for dataset1 to finish loading
$w("#dataset1").onReady(() => {
let itemObj = $w("#dataset1").getCurrentItem();
if (!itemObj.text === '') {
$w('#text12').collapse();
$w('#text13').collapse();
$w('#text14').collapse();
$w('#text15').collapse();
$w('#text16').collapse();
$w('#text17').collapse();
$w('#text18').collapse();
$w('#text19').collapse();
$w('#text20').collapse();
$w('#text21').collapse();
$w('#text22').collapse();
$w('#text23').collapse();
$w('#text24').collapse();
$w('#text25').collapse();
$w('#text26').collapse();
} else {
$w('#text12').expand();
$w('#text13').expand();
$w('#text14').expand();
$w('#text15').expand();
$w('#text16').expand();
$w('#text17').expand();
$w('#text18').expand();
$w('#text19').expand();
$w('#text20').expand();
$w('#text21').expand();
$w('#text22').expand();
$w('#text23').expand();
$w('#text24').expand();
$w('#text25').expand();
$w('#text26').expand();
}
});
});
Here are some photos:
Examples of prior code used (no success):
import wixData from 'wix-data';
$w.onReady(function () {
//Wait for dataset1 to finish loading
$w("#dataset1").onReady(function () {
//get the value
const textValue = $w('#dataset1').setFieldValue('');
//collapse the text box textValue is empty
if (textValue === '') {
$w('#text12').collapse();
$w('#text13').collapse();
$w('#text14').collapse();
$w('#text15').collapse();
$w('#text16').collapse();
$w('#text17').collapse();
$w('#text18').collapse();
$w('#text19').collapse();
$w('#text20').collapse();
$w('#text21').collapse();
$w('#text22').collapse();
$w('#text23').collapse();
}
});
});
Thank you!
I think the root of the problem is that I'm using the current item and not considering all the items. Tried replacing "getCurrentItem" with "getItems" to see the full data set, but for some reason, it isn't giving me any results at all. Here is the current code
import wixData from 'wix-data';
$w.onReady(function () {
//Wait for dataset1 to finish loading
$w("#dataset1").onReady(function () {
//get the value
let itemObj = $w("#dataset1").getItems( );
console.log(itemObj)
});
});
should work exactly the same as "getCurrentItem" but this time the console log is blank.
Anyone have ideas on why?
Hi,
If you want to collapse the text when the "weekdayHours4" field is empty you should remove the "!" sign from the beginning of the condition.
Still playing around with this—here my code:
// For full API documentation, including code examples, visit http://wix.to/94BuAAs import wixData from 'wix-data'; $w.onReady(function () { //Wait for dataset1 to finish loading $w("#dataset1").onReady(function () { //get the value let itemObj = $w("#dataset1").getCurrentItem(); if (!itemObj.weekdayHours4 === '') { //collapse the text box weekdayHours4 is empty $w('#text18').collapse(); } else { $w('#text18').expand(); } }); });
Unfortunately, I can only seem to get every text box to collapse regardless if they have content or not...
Thank you,
Colton
Hey Andreas,
I see what you are saying... I guess what I am trying to do is make the empty text-cells collapse if there isn’t text to pull from the dataset. Currently, I am left weird formatting with empty text-cells (no hours of operations put into those cells on the live side.
I am not sure how to resolve this honestly. Though I do feel I am close.
Thank you for your quick response.
Hey
In your code you are checking if the field with fieldKey text is equal to '' and I guess you have no fieldKey called text but you want to check a lot of fields is they are empty?
let itemObj = $w("#dataset1").getCurrentItem(); if (!itemObj.fieldKeyHere === '') { // Your stuff here // Collapse the text element that is empty }
So you can't check all at once as long as you don't loop through all controls and check the value in the fields after the page is rendered and then collapse those with empty strings inside.