Code for an autofill input

Hi everyone, thank you for reading my question :slight_smile:

I am struggling with my code, I really don’t know where the problem on my autofill input comes from.
So here is the thing : my input is showing “list of the cities” until I press an arrow down, which is not the behavior that it is supposed to be.

Here are some printscreen of the problem, and I will paste my code below

When typing letters

When pressing arrow down

And here is my code (don’t mind the last function, it’s related to the checkbox) :
For information, I borrowed and adapted this code from another user ( https://www.wix.com/corvid/forum/tips-tutorials-examples/example-repeater-dropdown-with-keyboard-navigation )

import wixUsers from 'wix-users';
import wixData from 'wix-data';

$w.onReady(function () {
 //TODO: write your page related code here...
});

const HL_COLOR = "rgba(190,190,250)";
const REG_COLOR = "rgba(222,222,222)";

let listSize;
let currIndex = -1;

$w.onReady(function () {
    $w('#city').onKeyPress((event) => {
        setTimeout(() => {
 if ($w('#city').value.length === 0) {
                currIndex = -1;
                $w("#repeater1").collapse()
                    .then(() => {
                        console.log("Done with collapse");
                    });
            } else {

 switch (event.key) {
 case "Enter":
                    $w('#city').value = $w('#repeater1').data[currIndex].title;
                    $w("#repeater1").collapse()
                        .then(() => {
                            console.log("Done with collapse");
                        });
 break;
 case "ArrowLeft":
 case "ArrowRight":
 break;
 case "ArrowUp":
 if (currIndex > 0) {
                        currIndex -= 1;
                        refresh_repeater();
                    }
 break;
 case "ArrowDown":
 if (currIndex < listSize - 1) {
                        currIndex += 1;
                        refresh_repeater();
                    }
 break;
 case "Escape":
                    $w('#city').value = '';
                    currIndex = -1;
                    $w("#repeater1").collapse()
                        .then(() => {
                            console.log("Done with collapse");
                        });
 break;
 default:
                    currIndex = -1;
                    wixData.query("cities")
                        .startsWith("title", $w('#city').value)
                        .ascending("title")
                        .limit(5)
                        .find()
                        .then((res) => {
                            $w('#repeater1').data = [];
                            $w('#repeater1').data = res.items;
                            listSize = res.items.length;
                            $w('#repeater1').expand();
                        });
 break;
                }
            }
        }, 50)
    });
});

export function rptDropdown_itemReady($item, itemData, index) {
    $item('#text18').text = itemData.title;

 if (index === currIndex) {
        $item("#box3").style.backgroundColor = HL_COLOR;
    } else {
        $item("#box3").style.backgroundColor = REG_COLOR;
    }

    $item('#container4').onClick(() => {
        $w('#city').value = itemData.title;
        $w('#repeater1').collapse();
    });
}

function refresh_repeater() {
    $w("#repeater1").forEachItem(($item, itemData, index) => {
        $item('#text18').text = itemData.title;

 if (index === currIndex) {
            $item("#box3").style.backgroundColor = HL_COLOR;
        } else {
            $item("#box3").style.backgroundColor = REG_COLOR;
        }

        $item('#container4').onClick(() => {
            $w('#city').value = itemData.title;
            $w('#repeater1').collapse();
        });
    });
}

 
export function checkbox1_change(event, $w) {
if ($w("#checkbox1").checked){
    $w("#poids").show();
    }
 else
    $w("#poids").hide();
}

Thank you so much for your help !

Hello, any suggestion ? :slight_smile:

Hello Valentin,

you want to realize something like this?

https://www.wix.com/gramps-workbench/repeater-dropdown

Hi Russian Dima :slight_smile:
Thank you so much for replying me ! Yes it’s exactly what I intend to do, except that my database is a bit different (it’s 28 000 cities) Thank you !

Then you have just to look for Yisraels-Template-Collection, you will find the Link on my little helping site…
https://russian-dima.wixsite.com/meinewebsite/blank-5
The example-template is called “Repeater Dropdown” and you can reconstruct it directly in your editor.

Take a look and try it out…

Hi ! Thank you for your answer :slight_smile:

Well, that’s what I did already (I mentionned it on my question :wink: ), but after reconstructing it as shown in my code previously I have this bug happening and I can’t figure out why…
:sob::sob::sob:

Ok, i take a look… (no promise that i can help you :grin::roll_eyes:)

Give me some facts.

You have a DATABASE, which column is relevant? (column-ID)
As i can see, a dataset is not needed, because Yisrael did it with a query.

The database (“Countries”) in this example consists of 1-column which is used → the first column (ID=title)

So i think you have just to change this 2-values.

(If you are not sure what to do, show a image of your database (just the 2 first rows and the relevant column are needed).

EDIT:


Ohh damn, the database is even included in Yisrael’s example.

I can’t thank you enough for the time you spend helping me. I will check your tip and will come back to you asap :slight_smile:

Valentin, all you have to do, are just 2-things.

  1. Replace Database-Name (“Countries”) with your own Database-Name.
    How is called your Database?

  2. Replace the column-ID (“title”) with your own colum-ID.
    What is the ID of the relevant column in your database?

My database is called cities
wixData . query ( “cities” )

On my database, the colum relevant for the cities have “title” for ID

By the way, I believe the query is working, I just have the “list of cities” text on my repeater until I press arrow down which then shows the cities.

Could you find the little bug?
Sorry, i can not see your project :grin:
Take a pic of your database (header + first row/vlaue)

(showing the id)

I have found the answer !

For those with the same issue, you just need to add a dataset and link the text to the title field of your database :grinning::grinning:

Be sure that all the permissions on your database are set to “Everyone” and on your dataset “read and write”, and be sure that your sandboxhave been synced.

@russian-dima yes i need this help

https://www.wix.com/gramps-workbench/repeater-dropdown

alguem tem o codigo do link acima:

Hi, this is great! Could you give me a hint on how to achieve this?