Hi,
I have a scenario where I am using a slideshow to simulate a wizard through which the user inputs data. Each slide represents a different section of data. The user clicks “next” through the various slides then on the last slide clicks submit. At this point all of the datasets are validated and saved.
But what I really want is for none of the data to be saved if there is an error in any of the datasets.
The scenario is this. At present, if dataset1 validates as its ok, and dataset2 has an error, dataset1 will be persisted and the form will be cleared. What I would like is for some pre-validation before saving, so if dataset2 contains invalid data, no data is saved even if dataset1 is fine.
So in summary, validation currently occurs in the dataset.save() method. What alternative approach could I use to validating the dataset without persisting it? I’ve looked at using data hooks but don’t see how they can help we pre-validation.
I am currently using the dataset.onerror() method to show errors to users.
Thanks
Wix do already do their own multistage form set up as an example here.
https://www.wix.com/corvid/example/multistage-form
Although it doesn’t save it to any dataset as you’re suggesting and it doesn’t save any of the users inputs in Wix Storage either as they move between slide.
You’re best bet is to just make up a mock form and use your code with the correct dataset id names and see if it works for you.
$w("#myDataset").onError( (operation, error) => {
let errorOp = operation; // "save"
ValidatableMixin - Velo API Reference - Wix.com
CMS: About Validation Settings for Input Elements | Help Center | Wix.com
Velo: About Validating User Input with Code | Help Center | Wix.com
There is already an existing Wix tutorial with validations set up that you can view in your Wix Editor roo.
https://www.wix.com/corvid/example/custom-validations
Using that example is exactly how I got to where I am now, and as you can see I am already using .onError from the code I posted. As you clearly pointed out the example doesn’t persist anything to a dataset so its not really of any relevance. So if anyone has any other suggestions that would helpful with multiple dataset validation I would appreciate it. I have looked through all of the links that you have posted before asking the question.
Thanks