I have an input field connected to a dataset, and the input writes to the “title” field in the dataset when I click my submit button. But is there a way to connect the input field to the dataset and the “title” field using code?
I’m comfortable using the Wix windows to do the job, but there are a couple of other things I need to do that require me to make these connections in the code instead. Basically, I’d like to change the dataset field the input writes to using a dropdown selection.
Any links available or direct help on this question would be much appreciated.
You can easily have a user input saved through the data connections on the page to whatever dataset field you want to link it to, providing that you are putting text to text field, number to number field, boolean to boolean field etc.
https://support.wix.com/en/article/creating-a-form-with-user-input-elements
After setting up your dataset, connect your elements to it.
-
Select an element in your form.
-
Click the Connect to Data icon.
-
Connect your element to the dataset.
-
Connect the element to a field in your Database Connection.
-
Repeat these steps for each user input element in your custom form.
You can see more here.
https://www.wix.com/corvid/feature/custom-forms
You can also do it through code with setFieldValue/setFieldValues along with save.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValues
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#save
Note that there are two forms of save as well, one for your dataset which is linked above and one for your data that is linked here.
https://www.wix.com/corvid/reference/wix-data.html#save
You can also use Insert.
https://www.wix.com/corvid/reference/wix-data.html#insert
Or update.
https://www.wix.com/corvid/reference/wix-data.html#update
There are bulk versions too if you are adding a lot of data.
https://www.wix.com/corvid/reference/wix-data.html#bulkInsert
https://www.wix.com/corvid/reference/wix-data.html#bulkSave
https://www.wix.com/corvid/reference/wix-data.html#bulkUpdate
Then there is insertReference for if you are using reference fields.
https://www.wix.com/corvid/reference/wix-data.html#insertReference
I’ve got this thing working beautifully, but I’ve decided to use several items as opposed to a lot of fields in one item. This makes the dataset look much more organized and makes it much easier to manage.
I can retrieve data from each item, but how do I save to a specific item?
Any links or example code snippets would be much appreciated?
P.S.
More specifically, I’m trying to set the field values for a specific item in my dataset.