Getting custom fields data

Struggling to get this right.
Members have a custom field that they input from a drop box. That drop box is the “Preferred Location” for them to work.

On a form on the site i’m trying to have the Location drop box option to be auto filled to the preferred location they chose when they signed up (theres 1000’s of locations, it’s meant to save them from scrolling down to choose their own).

What’s the most efficient way to do this? Have been trying a few solutions from this site but cna’t seem to get it to work.

Many thanks

Hi @miran-stubican ! To auto-fill the “Location” drop-down field on a form based on the “Preferred Location” that a member selected during sign-up, you can use Wix Code to retrieve the preferred location from the member’s profile and set it as the selected option in the “Location” drop-down field. Good luck!

Thanks Bamuu for the reponse!

This is the code I am using current…

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

$w.onReady(function () {
let currentUser = wixUsers.currentUser;
currentUser.getEmail().then(email => {
wixData.query("member/PrivateMembersData")
.eq("email", email)
.find()
.then((results) => {
$w('#input8').value = results.items[0].preferred-location;
});
});

and this is the error I am getting which I can’t seem to figure out…



Error: e.text is not a function

And then the input8 value isnt updated with the details.

Any Ideas how I can get past this? Still very veryyyy new to javascript

Solved! Pls let me know if there’s a more efficient way or if my coding will cause issues!

import { currentMember } from 'wix-members';
    currentMember.getMember()
  .then((member) => {
let prefLoc = null
    prefLoc = member.contactDetails.customFields
let prefLoc1 = prefLoc["custom.preferred-location"].value;
$w('#dropdown5').value = prefLoc1
  }
  )
  .catch((error) => {
    console.error(error);
  })

1 Like