(PROBLEM SOLVED) permanently active image after onclick

Hello and good morning :grin:.

Ok i improved the code for this function, now it should be much better than the first version of code.

Check it out :sunglasses::wink:

import wixData from 'wix-data';

//------------------------------------ USER-DATA-INTERFACE -----------------------------------------
var DATABASE =  "Switch-Save-Function"
var DATASET =   "dataset1"
//------------------------------------ USER-DATA-INTERFACE -----------------------------------------
var currentItemIndex

$w.onReady(function () {
    $w("#"+DATASET).onReady( () => {
        $w('#TXTmember').text="Member-"+currentItemIndex
        $w('#BTNsave').onClick(()=>{
 if ($w('#BTNswitch1').checked===true){$w("#"+DATASET).setFieldValue("btnStatus", true);}
 else {$w("#"+DATASET).setFieldValue("btnStatus", false);}
            $w("#"+DATASET).save();
        })

        $w('#BTNnext').onClick(()=>{console.log("NEXT")
            currentItemIndex = $w("#"+DATASET).getCurrentItemIndex()+1
            console.log(currentItemIndex)
            $w('#TXTmember').text="Member-"+currentItemIndex
        })

        $w('#BTNprevious').onClick(()=>{console.log("PREVIOUS")
            currentItemIndex = $w("#"+DATASET).getCurrentItemIndex()+1
            console.log(currentItemIndex)
            $w('#TXTmember').text="Member-"+currentItemIndex
        })
    })
});

I will write the new [How2] later :wink:

@russian-dima It really looks really good😁.

Thanks for the help and the effort to get back to me with the best project. Faithful follower now​:wink::heart_eyes::heart_eyes::heart_eyes::heart_eyes:

@russian-dima are you configuring your button like this?no Boolean value

Do not understand your question?
But if you want to know which buttons were used in this example, then you have 3x normal buttons + 1x Switchbutton.

1x Save-buton (normal button) - -----> connected with code
1x Next-button (normal-button) -----> connected with dataset & code
1x Previous-button (normal-button) ----> connected with dataset & code

1x switchbutton

Right.But I mean the value configured on the button: you can configure the value deleted or left empty.

Left it empty. You just need the boolean-function of it without any values, right? Set it to ----> OFF, although it does not realy matter, because it will be
controlled by the function automatically, when page loads. (You can test it).

@russian-dima The code worked perfectly, everything is set up as you wisely and patiently taught me (I love you for that).But, unfortunately, when I click the save button, the boolean value goes back to false, not respecting the choice I made that was true, even though it was recorded in the database.

Ok, let’s check what’s wrong with your code.

CHECK-LIST:

  1. All permissions given in the DATABASE?
  2. Dataset is setted to READ & WRITE?
  3. You modified all relevant options like “database-names” and so on?

Show, your end-code and the relevant databases and references, which are coneccted with your project.

@russian-dima

  1. All permissions given in DATABASE?
    A: YES!
  2. Is the data set set to READ & WRITE?
    A: WRITE
  3. Have you modified all relevant options like “database-dames” and so on?
    A: I’m not sure about that!
    Show your final code and the relevant databases and references, which are connected with your project.


import wixData from ‘wix-data’ ;

var DATABASE = “Switch-Save-Function”
var DATASET = “dataset1”

$w.onReady( function () {

checkStatus() 

});

function checkStatus (parameter) {console.log( “check started” )

wixData.query(DATABASE) 

.find() 

.then( (results) => { 

if (results.items.length > 0 ) {console.log( “GO” )

let firstItem = results.items[ 0 ]; //see item below

let currentItemIndex = $w( “#” + DATASET).getCurrentItemIndex()

let currentItem = results.items[currentItemIndex]

let myBoolean = results.items[currentItemIndex].btnStatus

if (myBoolean === true ) {$w( ‘#BTNswitch1’ ).checked = true }
else {$w( ‘#BTNswitch1’ ).checked = false }

        console.log(currentItemIndex) 

        console.log(myBoolean) 

    }  

else {console.log( “Nothing found.” )}

}) 

. **catch** ( (err) => { 

let errorMsg = err;

} ); 

}

export function BTNswitch1_click(event) {
checkStatus()

}
export function BTNsalve_click(event) {
save_Data()
}

function save_Data (parameter) {

var currentItemIndex

$w.onReady( function () {
$w( “#” +DATASET).onReady( () => {

    $w( '#BTNsave' ).onClick(()=>{ 

if ($w( ‘#BTNswitch1’ ).checked=== true ){$w( “#” +DATASET).setFieldValue( “btnStatus” , true );}
else {$w( “#” +DATASET).setFieldValue( “btnStatus” , false );}
$w( “#” +DATASET).save();
})

}) 

});

}

Ok there are some errors, i think you are now mixing my 1-version with my second one.

Try never to use more then one onReady-command. The more you will use “onReady”-commands the slower will be your code.

Ok, now do the following. DELETE all your CODE which you have posted in your last post and put this one into your code-section…

import wixData from 'wix-data';
//------------------------------------ USER-DATA-INTERFACE -----------------------------------------
var DATASET =   "dataset1"
//------------------------------------ USER-DATA-INTERFACE -----------------------------------------
var currentItemIndex

$w.onReady(function () {
    $w("#"+DATASET).onReady( () => {
        $w('#BTNsave').onClick(()=>{
 if ($w('#BTNswitch1').checked===true){$w("#"+DATASET).setFieldValue("btnStatus", true);}
 else {$w("#"+DATASET).setFieldValue("btnStatus", false);}
            $w("#"+DATASET).save();
        })
    })
});

Connect a dataset to your choosen database and modify the right input in "USER-DATA-INTERFACE (look into my CODE, you will find it there.)

This code is the minimum, what you will need to run it.
All other stuff is not necessary.

Put 3 normal-buttons + 1x switchbutton onto your page.
Connect two of the normal buttons (NEXT & PREVIOUS) with the dataset, for switching the items.

CHECK if you have connected and modified RIGHT :grin: and start a test.

@russian-dima REALLY!I did the tests and now the select button and the send are connecting to the database and the database is returning the command to them.Thanks again.Sorry for the excess of questions.Congratulations on the excellent work.If I were Wix I would hire you as a consultant.Your tutorial page is in my favorites of favorites

PROBLEM SOLVED BY @russian-dima :nerd_face::nerd_face::nerd_face::nerd_face::grin::heart_eyes:

:rofl:Thanks for compliment.

Try to understand the code. :wink:
I will complete this little example-tutorial the next days, so you can read it one more time in the new updated version.

I hope you could learn a little bit. If you will need help in future, you know where to find me xD.

Have a good weekend!