Question:
How can i update nicknames for all my site members to Firstname + Lastname
Product:
WIX studio Editor
What are you trying to achieve:
The default nickname on my members when I imported them has been set to the first part of their email address. I would like it to be Firstname + Lastname
What have you already tried:
Checked the forum
Additional information:
In particular, this information is useful in determining who else is going to an event
1 Like
You will either have to do it manually, or write Velo code that will update each memberās nickname one by one.
Cant get nickname on the members page. Any ideas
Hi Pratham.
Thanks for your suggestion.
Sadly i dont know how best to integrate velo to the website.
Im happy to set it manually but unfortunately cannot see how to add that field to either the member manager or contact collections.
Can you help please
Do you not see the Nickname field in the Members/FullData collection?
Hi Pratham. I can indeed see the field in the collection, but cannot get it exposed to the MyAccount page to maintain
Can you elaborate more on what do you mean by that?
Your query was how to update memberās nicknames, which as I said, you can change in the Members/FullData collection, and that will automatically update it in the Members/PublicData collection as well.
Now if I understand correctly, you want to show this nickname field on your memberās my account page so that they can edit / change it?
From what it looks like, there is no option to add a nickname field right in the memberās area itself along with other fields. Which is why the only way you can do it now is using Velo, where you can fetch the nickname using the getMember() function. You will have to write additional code if you want them to be able to change it as well.
That is exactly what I need to do. Have an editable field on the MyAccount page.
Unfortunately, whilst I am not new to coding, I am new to velo.
Do you per chance have an example velo code that does something similar?
Hereās how to do that:
In your backend, create a web.js module called updateMember.web.js
Remove any default code and paste this code in your newly created backend file:
import { Permissions, webMethod } from "wix-web-module";
import { members } from "wix-members.v2";
export const updateMemberDetails = webMethod(
Permissions.Anyone,
(memberDetails) => {
return members
.updateMember(memberDetails._id, memberDetails)
.then((member) => {
return member;
})
.catch((error) => {
console.error(error);
});
},
);
Then in your frontend, on your memberās account page, add a text input element and a button. This is what your members will use to update their nickname.
Paste this code in your frontend:
import { currentMember } from "wix-members-frontend";
import { updateMemberDetails } from 'backend/updateMember.web';
var memberDetails;
$w.onReady(function () {
currentMember
.getMember({ fieldsets: ['FULL'] })
.then((member) => {
memberDetails = member;
$w('#input1').value = memberDetails.profile.nickname;
})
});
$w('#button1').onClick(async (event) => {
if ($w('#input1').value) {
memberDetails.profile.nickname = $w('#input1').value;
$w('#button1').disable();
let updatedDetails = await updateMemberDetails(memberDetails);
$w('#input1').value = updatedDetails.profile.nickname;
$w('#button1').enable();
}
})
#button1 will be the ID of your button and #input1 will be the ID of your input element.
If you see any red lines in the code, make sure to change the element IDs and you should be good (:
Hi Pratham.
Thanks for the suggestion which makes sense to me.
However I cannot get the developer into edit mode and some of this may be above my skill set. Iād like to not mess up the site whichis all but complete apart from this element.
Appreciate this is quite cheeky, but is there any chance we can collaborate on a call and you talk me through how to set this up please.
i can add it into wix.ide but get an error on line 1
Hey there,
Donāt worry, you cannot technically āmess upā the site through the code panel; and even if you do, you always have the option to delete the code and revert back to a previous version of the site using the Site History feature.
About the error that you just pointed out, it happens to appear only in the IDE and is more of a warning than an error, and can safely be ignored.
Now that you have pasted your backend code correctly, all you need to do now is locate your My Account page code file under >pages and copy paste the frontend code there, like so:
And finally, make sure your IDs match your actual input field and button in the editor and publish the site.
Hi Pratham,
believe it or not the field was hidden hence why it did not appear. it now does and also allows me to edit it from the MyAccount page without needing any velo code. so Iām happy with that.
however, i would like to systematically run through the entire collection and amend all nicknames to be concatenate(Firstname, " ā, Lastnameā).
is there a mechanism to do this in velo - Iām happy to have a dummy page rather than mess an existing one
Hi Pratham.
got help from a JS expert and itās now working.
thanks for your help - much appreciated
Glad to know that it worked out! 