I am creating a store where people may customize their products. I need to know what options they have selected so I added check-boxes to the page.
I have put the function on click to some buttons so when a user clicks it the boolean is set to true, this isn’t working. I am able to collect the the data that the user input only by having them directly click on the check-boxes, I am not able to do it when the button is clicked.
At the end my intention is to have the check-boxes hidden so the user may not see them.
In order for us to be able to assist, you will need to provide more information. Show us the relevant code. What works? What doesn’t?
This works:
Clicking on the checkbox directly.
The check-boxes and submit button are connected to the data.
I am able to see this in the content manager when user clicks on submit button.
This is how I want it to work but it does not:
Clicking on a button, that enables an overlay to let users know what they have selected and at the same time sets the boolean to true.
After a user clicks on the submit button the content manager is empty and it does not tell me what they have selected.
Here is the code:
//--------------------------Lens Use Logic------------------------------//
// What happens when a user clicks on lens use ‘non prescription’ button.
export function lensUseButtonNonPrescription_click(event) {
//Show lens use overlay ‘non prescription’:
$w( ‘#lensUseOverlayNonPrescription’ ).show();
//Check lens use checkbox ‘non prescription.’
$w( ‘#nonPrescriptionCheckbox’ ).checked = true ;
//Hide other lense use overlays.
$w( ‘#lensUseOverlaySin’ ).hide();
//Uncheck other lens uses checkbox’s.
$w( ‘#singleVisionCheckbox’ ).checked = false ;
//Enable the next button.
$w( ‘#nextButtonStep1’ ).enable();
}
// What happens when a user clicks on lens use ‘single vision’ button.
export function lensUseButtonSingleVision_click(event) {
//Show lens use overlay ‘single vision’:
$w( ‘#lensUseOverlaySin’ ).show();
//Check lens use checkbox 'single vision.
$w( ‘#singleVisionCheckbox’ ).checked = true ;
//Hide other lens use.
$w( ‘#lensUseOverlayNonPrescription’ ).hide();
//Uncheck other lens use.
$w( ‘#nonPrescriptionCheckbox’ ).checked = false ;
//Enable ‘next’ button.
$w( ‘#nextButtonStep1’ ).enable();
}
Same problem here. Strangely when setting the Checkboxes value by code it returns to its previous value right before submitting the data. I’ll let you know when i solved it. Help is appreciated!
Ok, this one was a pretty quick fix:
https://www.wix.com/corvid/forum/community-discussion/setting-a-boolean-value-to-true-by-a-button-click
Instead of sending the data to dataset via wix preset connections, manually write it into the dataset like @anthonyb described.
I changed a boolean to become true when a specific dropdown item has been selected by:
let variable = false ;
if ($w( ‘#dropdown1’ ).value === ‘Value1’ ) {
variable = true
}
$w( “#Dataset” ).setFieldValue( “FieldKey” , variable);