Hi
This is my first post on here and first site I’m building using Wix. I’m certainly no expert when it comes to building websites but I have done it before and do have some knowledge and understanding of things like HTML.
I’ll get to the point. I want to give site members the ability to change the privacy of certain fields. So for example. A field named “Surname” is set to Private by default but if they want to make this visible to people they can simply change the privacy to “Public”.
I have had a look online and everything seems to be about how I change a fields privacy which is straight forward and not what I am looking for.
Thanks in advance.
Stephen
There is no out of the box solution to change individual fields to be public/private.
You would need to custom code this functionality.
This is a bit complex, especially using Wix’s Member system
Wix uses its own default member data collections, with their respective access permissions, those are not controllable or editable
For that, you will need to create a new CMS collection for any extra data you want to save about your users - such as their privacy choice
So, let’s say we’ve made the collection called Members, set its permissions so that only the record owner can view data, and within it, we add a text field called surname, a boolean field/column called publicSurname and the _id column is set to the same id as in Wix’s member collections
You will need to set up client- and server-side code to securely fetch the details if the requirements are met, something along these lines:
Dynamic Member page:
import { getSurname } from 'backend/members.web.js'
// Assumptions for mock code:
// #surname is a text element, hidden by default
// #dynamicDataset holds the member data
const dataset = $w('#dynamicDataset')
dataset.onReady(() => {
const member = dataset.getCurrentItem(), // the member's public data
surname = await getSurname(member._id)
if (surname) {
$w('#surname').text = surname
$w('#surname').show()
}
])
backend/members.web.js
import { Permissions, webMethod } from 'wix-web-module'
import wixData from 'wix-data' // alternatively, use @wix/data
export const getSurname = webMethod(Permissions.Anyone, async memberId => {
const member = await wixData.get('members', memberId)
if (member.publicSurname) return member.surname
}