WIX Ideas Team
Have you wanted to save data from a calculated field? Then you are in the right place.
Saving a solution or answer to WIX database collection is easier than expected. Using WIX Data Hooks, it is absolutely achievable to save a calculated field before it is inserted into the database.
WHAT I DID
The steps to achieving this procedure is quite basic. Assuming you already know the formula to use then the rest is merely assigning your answer to the answer field in your database. Before adding the code, I connected my form element(Date Picker) to data. WHY? The date picker value (Year selected) is what I used for the calculation. So it was important I took the value from there and substracted from the current year using new Date() object. I then added my data hook from by clicking on the three dot icon option for my database and clicked on Add/Remove Hooks.
Next I added the beforeInsert function and started modifying my code. My edited code looked something like that.
In order to calculate the date picker field, I decided to intercept the values before it was inserted and used it to calculate for the age. This date was then saved in a field in my database. Eventually, I will use this field in my website displaying it or using it for another operation it comes to that.
Well, that rounds up technically every step. My final code is below and you can copy and paste for personal use. I hope you enjoyed this tutorial, don't forget to LIKE/SUBSCRIBE
LEAVE A COMMENT
Thanks for leaving a comment🎉
RELATED TUTORIALS 🚀