Hello, long time reader first time poster here. I’m working on a project right now that has me stumped. I have a multi-state box with multiple pages. Each page has multiple buttons on them (not input selection tags). The idea is as a user clicks the button it moves the person to the next page and the text on that button gets captured in the dataset. Here is the code I have so far for one of the individual buttons. This code is working to advance the user to the next page but is giving an error message on the data collection. I cannot figure out what I’m missing to get this to work. Thanks in advance for any help.
$w ( “#PurchFormButton2o1” ). onClick ( function () {
$w ( “#dataset1” ). setFieldValue ( “Type of Home” , “Single Family Home” );
$w ( “#dataset1” ). save ();
$w ( “#PurchaseForm” ). changeState ( “Credit” );
});
Hi Ray! What error message is it giving you? Without more information, my guess is that you are advancing the multi-stat box before the dataset has finished saving. Try changing your code like this: $w(“#PurchFormButton2o1”).onClick(function () {
$w(“#dataset1”).setFieldValue(“Type of Home”, “Single Family Home”);
$w(“#dataset1”).save()
.then ((item) => {
$w(“#PurchaseForm”).changeState(“Credit”);
});
});
This way you wait for the dataset to finish saving and then advance the multi-state box.
Also, if the next multi-state box page is dependent on the information you just saved, you’ll need to do a refresh on the dataset: $w(“#dataset1”).refresh();
@robmich
Hi Rob, here are the error codes:
Running the code for the Purchase Form page. To debug this code in your browser’s dev tools, open a6ibw.js.
Error: Some of the elements validation failed
UserError: datasetApi ‘save’ operation failed Caused by DatasetError: Some of the elements validation failed
Caused by: DatasetError: Some of the elements validation failed
UserError: datasetApi ‘save’ operation failed Caused by DatasetError: Some of the elements validation failed
Caused by: DatasetError: Some of the elements validation failed
Error: Some of the elements validation failed
You have unhandled error in async operation. Consider catching it and handling accordingly. DatasetError: Some of the elements validation failed
@raygrewe Hi Ray. Some of the fields attached to the dataset are failing validation. Most likely they are fields that are in the multi-state box that are set to required. Try removing the required flag from all of the fields and see if that works. If it does, then you can work out a better flow for entering required fields and saving the data.
@robmich Went through all of the inputs and removed all required fields. That helped, and reduced it down to three error codes:
Running the code for the Purchase Form page. To debug this code in your browser’s dev tools, open a6ibw.js.
UserError: datasetApi ‘save’ operation failed Caused by DatasetError: Operation (save) not allowed during save
Caused by: DatasetError: Operation (save) not allowed during save
Just out of curiosity I removed the save portion to the code:
$w ( “#dataset1” ). save ();
After I removed that, it worked! Not sure why it wouldn’t want that, but I guess some times less is more, ha! Here’s what the functioning code looks like:
$w ( “#PurchFormButton2o1” ). onClick ( function () {
$w ( “#dataset1” ). setFieldValue ( “Type of Home” , “Single Family Home” );
$w ( “#PurchaseForm” ). changeState ( “Credit” );
});
Rob, can’t thank you enough!