My filtered dataset displays blank repeater

I’m using this code to filter my dataset based one text input field:

// For full API documentation, including code examples, visit https://wix.to/94BuAAs
import {local} from 'wix-storage';
import wixData from 'wix-data';

$w.onReady(function () {

    $w('#search').onClick(()=>{
 if($w("#sourceaccount").value!==""){
            $w('#group6').hide();
            $w('#group7').hide();
            $w('#group8').hide();
            $w("#dynamicDataset").setFilter(wixData.filter()
                .startsWith("username", $w("#sourceaccount").value));
        }else{
            $w('#group6').show();
            $w('#group7').show();
            $w('#group8').show();
            $w('#dynamicDataset').setFilter( wixData.filter() );
        }
    });
})  

When I click the search button with the input field populated, the repeater is blank. Please help!

You might check the field key, that it is “username” and not “userName” or “UserName”.

Did you try the following at the beginning of the onClick function?

console.log($w("#sourceaccount").value)

Do you have a value that exists in the username field of the collection?

You might also need to use a timeout to ensure that the the text input value was updated. See Give the TextInput onKeyPress Function some time.

Thx for the suggestion. I double checked and although the field name is “Username”, the field key is “username”. So that’s not it.

Thx for the suggestions. I’m getting the right value when I output to the console log.

I applied the timeout as well, setting it to diff values ranging from 100 - 3000 milliseconds. That didn’t work either.

One thing I did notice is that when I applied the filter to the dataset using the ‘Settings’ modal and then published it, the page broke with a 404 error. I’m also noticing that the dataset’s Filter modal sometimes opens up and is blank, causing me to close it and try again. So its appearing more and more to be an issue with the dataset behaving in an inconsistent manner.

Please post the URL of your site.

Not sure what happened but its working now!