Hi Alvaro,
If you would like to have the button save as “disabled” for only the current user, then you could use the wix-storage approach mentioned by Sapir.
If you would like to have a change made by one user then appear to an entirely different user, then you would want to save the changes in a Collection (i.e. in the WIX Database for your website), and read/query those values for each user of your website.
Below is code for Sapir’s approach:
import {session} from ‘wix-storage’;
$w.onReady(function () {
// this code is for when the page is reloaded or can go within any page on the website
if(session.getItem("myButtonValue") === "disabled"){
$w('#myButton').disable();
}
else{
$w('#myButton').enable();
}
})
export function myButton_click(event) {
session.setItem(“myButtonValue”, “disabled”); // called when user clicks the button to disable
}
To be able to share the change with other users, here is a general code example:
// PAGE 1 - CODE
import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
export function btnSubmit_click(event) {
//Add your code for this event here:
let toInsert = {
"formValue1": $w("#myButton").value,
"settingId": "myButtonValue"
};
wixData.insert("SettingsValues", toInsert)
.then( (results) => {
console.log("Form results submitted.");
} )
.catch( (err) => {
console.log(err);
} );
}
// PAGE 2 - CODE - FOR ALL OTHER MEMBERS TO SEE THE CHANGE
import wixData from ‘wix-data’;
import wixUsers from ‘wix-users’;
$w.onReady(function () {
loadData();
})
function loadData() {
wixData.query("SettingsValues")
.eq("settingId", "myButtonValue")
.find()
.then( (results) => {
let firstItem = results.items[0];
if(firstItem.formValue1 === "disabled"){
$w('#myButton').disable();
}
else{
$w('#myButton').enable();
}
})
.catch( (err) => {
console.log(err);
} );
}
Note that the above WIX Code assumes that the Collection name is “SettingsValues” and the fields of that Collection are named: “formValue1”, “settingId”. And, the following are the names of user input controls on both the member and non-member pages: $w(“#myButton”).
Hope this helps.
Nick