save data to collection from lightbox

Hello,

I have a ‘submit’ page where there are various inputs from users and upon clicking “submit” the info is going to be saved in a collection.

I also have 2 lightboxes on the same ‘submit’ page, which I want users to click BEFORE they submit the whole page, and the users should click some ‘checkbox’ buttons inside the lightboxes, click ‘save’ in the lightboxes, and this will save additional data to the collection and return to the ‘submit’ page.

What currently I can’t figure out is:

  1. is it possible to save data this way into a collection?

  2. should I instead save the selections people made in the lightboxes and only the main ‘submit’ will push that into the collection? if so, how do I do that?

  3. I have some code trying to save to a collection from the lightbox checkboxes upon ‘save’:

import {ifc_data}
from 'backend/ifc_data.jsw';
var picks = [];
export function checkbox1_click(event, $w) {
	picks += 'compact volume';
}
export function checkbox3_click(event, $w) {
	picks += 'advanced envelope';
}
$w("#ifc_data").onReady(function () {
	$w("#ifc_data").setFieldValue("strategies", picks);
});
console.log(ifc_data);
console.log(picks);

The error in the console log is :
“Error: The element selector function (usually $w) cannot be used before the page is ready”

Would appreciate any help on these issues,
Thanks.

Hi Yafim, did you ever solve this problem ? I have the same error for a different scenario…

Hi Roi Bondi,
Can you please explain what you are trying to achieve?
Please share your url so we will try to reproduce.
Roi.

My issue was solved. On to the next issue :slight_smile:
Thanks.

Shouldn’t this be the way to achieve it?

$w.onReady(function () {
$w(‘#ifc_data’).onBeforeSave(() => {
$w(“#ifc_data”).setFieldValue(“strategies”, picks);
$w(“#ifc_data").save();
});
});

That said, I’m having issues with save on lightboxes. The code seems to work find in dev. However, in the live environment, I get the following error from the javascript console and sometimes not all the data saves properly.

Also, onAfterSave does not seem to work at all.

I find lightboxes very powerful. However, there seems to be some issues.