(SOLVED) - What am I missing? (syntax problem?)

Hi,

I want to make a text box to show if a specific value is found inside another text box. I use the following:

$w.onReady (function() {
 if ($w("#counter").text === 448) { 
         $w("#text29").show();
   }
else {
  $w("#text26").show();
 }
});

#counter text box gets dynamically its value from here:

export function table1_dataChange(event) {
 let count = $w("#dataset1").getTotalCount(); 
    $w("#counter").text = String(count);
}

Problem: text box #text29 never shows up, although #counter shows a value of 448. What am I doing wrong?

Hello,

“counter” is a textfield?

Counter.text —> what does it say? Isn’t it a —> STRING ? (.text)
But 448 is a NUMBER, right? → could this be the problem ?

Try —> “448” something changed?

Play around and convert from STRING into NUMBER, or NUMBER into STRING. Did you get your goal ?

It is a string yes, as I say in my example above. I tried the ‘448’, no luck.

If I convert $w( “#counter” ).text = String (count); to $w( “#counter” ).text = Number (count);, the getTotalCount doesn’t work, I get no results. Back to string and I get all my db’s results in the text box.

@gemats

I think you are not very new to coding. Try to work more with → CONSOLE-Logs.

export function table1_dataChange(event) {
 let count = $w("#dataset1").getTotalCount(); 
 console.log("COUNT = " + count)
 console.log("Type of COUNT = " + typeof count)
    $w("#counter").text = String(count);
}

With such little helping logs, you always can see what happens.

1 Like

@gemats You should put everything in $w(“#dataset1”).onReady(() => {/here/})

2 Likes

@jonatandor35
Yes J.D. is right, you forget once again, that first everything has to be loaded, before you want to get some results.
It is now the second time, where “onReady” makes troubles for you.
You remember…

  1. Async-Await
  2. .then()
  3. onReady
    :wink:

Thanks J.D. did not see it.

But don’t worry. i have also sometimes troubles to use this knowledge. :grin:

1 Like

@jonatandor35 @russian-dima by everything, you mean of course the conditionals if-else and not the export function. So something like this? If yes, it doesn’t work. Counter stops working at all. Somehow it takes precedence over the export function to calculate the getTotalCount.

$w("#dataset1").onReady(() => {
 if ($w("#counter").text === "448") { 
         $w("#text29").show();
   }
else {
  $w("#text26").show();
 
}

});

@gemats
ok, try something like this one…

$w.onReady (function() {
    $w("#dataset1").onReady(async() => {
 let count = await $w("#dataset1").getTotalCount(); 
        console.log(count)
        $w("#counter").text = count.toString()
 
 if ($w("#counter").text === "29") { 
                $w("#text29").show();
        }
 else {
        $w("#text26").show();
        }
    })
});
  1. When your page is ready…
  2. And your dataset is ready…
  3. then count items of dataset1 (getTotalCount)
  4. show result in console
  5. set text (“counter”) to ----> amount of counted items and convert it into a STRING.
  6. following if-else-part

But there is some more in this CODE! What is defferent? What is NEW and what does it do?

By the way —> 29 is for my dataset (i have 29-items in my TEST-DATABASE.
You will use your own number of course (448)

@russian-dima

@gemats . getTotalCount (); is not a promise. So remove the “async” and the “await” from Dima’s code.

1 Like

@jonatandor35
I don’t know why but for me it works ?
Or am i understanding something different?

Here an working example…
https://www.media-junkie.com/counter

Edit: But you are right J.D., it works also without Async-Await (so it is not really needed at this case).

Edit-2: and this is the working code…

$w.onReady (function() {
    $w("#dataset1").onReady(() => {
 let count = $w("#dataset1").getTotalCount(); 
        console.log(count)
        $w("#counter").text = count.toString()
 
 if ($w("#counter").text === "29") { 
                $w("#text29").show();
        }
 else {
        $w("#text26").show();
        }
    })
});

@russian-dima adding an unnecessary “await” to a non-promise function shouldn’t make a problem, but removing all the unnecessary code may help locating the issue.

George, please post your code.

@jonatandor35 Yes of course, that makes sense.

@jonatandor35 So, this is the Live Page :
https://gemats.wixsite.com/gkmatsaridis/law-database-1

These are the hidden boxes I want to show/hide according to getTotalCount number (which for this example’s sake let’s say it’s the number ‘446’, could be anything though).

And this is the complete code on that page. Most of it are nicely working export functions for my tooltips (small question marks below the dropdown menus):

$w.onReady (function() {
    $w("#dataset1").onReady(async() => {
 let count = await $w("#dataset1").getTotalCount(); 
        console.log(count)
        $w("#counter").text = count.toString()
 
 if ($w("#counter").text === "446") { 
                $w("#text29").show();
        }
 else {
        $w("#text26").show();
        }
    })
});

export function table1_dataChange(event) {
 let count = $w("#dataset1").getTotalCount(); 
    $w("#counter").text = String(count);
}


export function hoverZone_mouseIn(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverEfarmostiki').show();
    $w('#checkbox2').hide();
    $w('#vectorImage3').hide();
    $w('#hoverBox').show();
}

export function hoverZone_mouseOut(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverEfarmostiki').hide("fade");
    $w('#checkbox2').show("fade");
    $w('#vectorImage3').show("fade");
    $w('#hoverBox').hide("fade");

}

export function hoverzoneEfarm1_mouseIn_1(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverYpoyrgeio').show();
    $w('#hoverboxYpoyrgeio').show();
    $w('#hoverzoneEfarm').hide();
}

export function hoverzoneEfarm1_mouseOut(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverYpoyrgeio').hide("fade");
    $w('#hoverboxYpoyrgeio').hide("fade");
    $w('#hoverzoneEfarm').show("fade");
}

export function hoverzoneIsxyon_mouseIn_1(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverboxIsxyon').show();
    $w('#hovermainIsxyon').show();
    $w('#vectorImage2').hide();
    $w('#checkbox1').hide();
}

export function hoverzoneIsxyon_mouseOut_1(event) {
 // This function was added from the Properties & Events panel. To learn more, visit http://wix.to/UcBnC-4
 // Add your code for this event here: 
    $w('#hoverboxIsxyon').hide("fade");
    $w('#hovermainIsxyon').hide("fade");
    $w('#vectorImage2').show("fade");
    $w('#checkbox1').show("fade");
}



@gemats I don’t see any problem with your code (unless the dataset is set to “write only”).

(But to be sure, remove the “async” and the “await”),

If that doesn’t work, post your question in the “rolling out improvements” thread.

@jonatandor35 Async and await removed. Still no progress. Neither text box is shown up meaning neither IF nor ELSE are being processed… If you don’t have any other idea, I’m heading to ‘rolling out improvements’ section… (db not in write only).

@J. D. Also, console.log (count) returns NULL… ???

@gemats yes. I saw that on your site. No idea. It looks like something for the ‘Rolling out’ thread.

But I’d first try to remove everything from the code except for the code that is inside the $w.onReady(). Just to make sure it’s not something in the other code (it’s probably not),