Hi all have the following code, can i use this somehow? to slice the first four characters of ${firstName} in text102
and then only show text102 to non-logged in users
$w.onReady(() => { $w("#dynamicDataset").onReady(() => { const item = $w("#dynamicDataset").getCurrentItem(); const firstName = item.firstName;
$w('#text102').text = `Say hello to ${firstName}`; }) }) }) let user = wixUsers.currentUser; let isLoggedIn = user.loggedIn; $w.onReady(() => { if (isLoggedIn) { doIfLoggedIn(); } else { $w("#columnStrip13").expand(); $w("#columnStrip12").collapse(); } wixUsers.onLogin(u => { isLoggedIn = u.loggedIn; doIfLoggedIn(); }) function doIfLoggedIn() { $w("#columnStrip12").expand(); $w("#columnStrip13").collapse(); }
ok hopefully i can simplify this, please do not worry as the dataset has already been filled previously
i have the following text element
#text1 that i would like to do the following with
$w('#text1').text = ` ${fieldKey} (slice2 characters and add 1 character space) ${fieldKey}`;
is this possible please
Thanks
Adam
Thanks guys, so the only answer i can give you is that a dynamic dataset that has been pre-populated and saved before a non-logged in user arrives at this page shows all the fields that i've connected
the code at the top of this page shows two different columnstrips and i have placed two different text strings in those
1, One which welcomes a logged in user personally i.e. welcome Joe to Adam's page
the other
2. for a guest i.e. welcome guest to Adam's page (Adam being a fieldkey name and field- already in the collection)
but both show a fieldkey of first name which is fine
so on this is about using another text string but this time slicing the field and placing the code somewhere in the not logged in code section above
I am like J.D. here and slightly confused as well.
If the user is logged in then you can get their firstname either by use of code and display it in a text box like you have done, or you simply link a textbox to your members dataset and it will simply show the name from the firstname field of that logged in user.
However, as J.D. has already said above, if the user is not logged in, then you will not have any firstname data to use from the dataset and the value will be undefined and return nothing.
Are you creating another form that non logged in users are using before they get to this stage of showing their first name? Like if somebody contacts you through your website and they are given a contactId for example?
If it is then you would need to be explaining that to us here so that we understand your process and not make it sound like you are trying to show a logged in users firstname to a non logged in user.
Another way to do this if you don't want them to be made as contacts on your site, is to just make use of Wix Storage API and save the firstname value and then recall it in the form that you need it on. That way you are not having to have an additional database just for this
https://www.wix.com/corvid/reference/wix-storage.html
Or do you have a set default value that you want to be put in the text box if the user is not logged in and it only changes if the user is logged in?
If this is not what you are doing, then please explain more.
The fieldkey already exists (has already been created and stored in the collection, so is defined it just needs to be sliced.
It's not easy to understand from your code what exactly you're trying to do.
Can you add more details?