Dropdown placeholder needs to be value from page

Hi. I have a site with dynamic pages. On this site I have dropdown linked to a database. I like the placeholder to be equal to a text field (that is dynamically populated) of the site.

I have tried: $w(“#dropdown1”).placeholder = $w(“#text20”) ;

But this does not work, unfortunately I am not experienced enough to find the alternative. Can somebody help out?

Thank you.

Hey,
You can try:

$w("#dropdown1").placeholder = $w("#text20").value;

Note that this should be added to the onReady function.

Should the issue persists, please sent us a screenshot as an example so that we can better understand the use case.

Tal.

Hi Tal,

Thanks for your feedback, tried your suggestion and it did not work. I got the following message:
Wix code SDK Warning: The placeholder parameter that is passed to the placeholder method cannot be set to null or undefined.

Made me think and tried something else:

Try 1


Result


Try 2


Result:


Hope I am getting close, but not there yet. Any suggestions?

PS above is just a very basic test website to try to get this issue resolved.

If the value comes from a database, you need to wait for the dataset onReady as well. It normally looks like the following -

$w.onReady(() => {
  $w('#dataset1').onReady(() => {
    $w("#dropdown1").placeholder = $w("#text20").value;
  });
});

The reason - you have to wait for the page to be ready for APIs, then wait for the dataset to have the data from the database.

Hi Yoav,

Thanks for your suggestion. Tried to add your suggested line, but still get same error:
Wix code SDK error: The placeholder parameter that is passed to the placeholder method cannot be set to the value [object Object]. It must be of type string.

Code now looks like:

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

$w(“#dataset1”).onReady(() => {
let text = $w(“#text20”);
$w(“#dropdown1”).placeholder = text;
});

Hi,

See me inline comment:

$w("#dataset1").onReady(() => {
       let text = $w("#text20").text; //Add .text to grab the actual text string
       $w("#dropdown1").placeholder = text;
 });

Hi Ido,

Thank you for your help, the last missing piece of puzzle.

Code now looks like this:

$w(“#dataset1”).onReady(() => {
let text = $w(“#text20”).text;
$w(“#dropdown1”).placeholder = text;
});

The placeholder value in the dropdown menu is now properly populated.

hello, someone can help on this?

already linked dropdown1 to dataset1(7 US regions), and code as below

$w.onReady( function () {
$w(“#dataset1”).onReady(() => {

$w(“#dropdown1”).placeholder = “please input your region”

});

when preview, can’t display “please input your region”, it go to one region directly, like this

Thanks in advance!!!