I created a form which, among other things, stores a text value in a user input box (read-only) when a button is clicked running the code $w(‘#inpAllDayDeal’).value = “48”;. The initial value of the box has been set to “none” and “10” in my testing. It all works fine, except when SUBMITted, the the database field contains the initial value, not “48”. I’ve tried unchecking read-only, but the only thing that works is if I input the value manually.
Read the Wix API reference for it - https://www.wix.com/corvid/reference/$w.TextInput.html#value
value
Sets or gets a text input’s value.
Description
To reset the text input, restoring any placeholder text, set the value property to null or undefined.
Note
Changing a text input’s value in code does not trigger an onChange event.
Using the Input Settings panel in the Editor you can set the type of a text input. That type is used only for validation purposes. The value returned by the value property of a text input is always a string, regardless of the type set in the Editor.
If an element is connected to a dataset, setting the element’s value in code does not set the value of the connected field in the dataset. That means if you use the dataset to perform a submit, the value changed in code is not reflected in the submitted item.
To submit the new value using a dataset, set the field’s value using the setFieldValue() function before performing the submit.
Thank you, givemeawhiskey, I have tried setFieldValue() but have managed only to add nonsense fields to the database. I’m 80 yo and new to Corvid, so I’ll just have to work out what I don’t understand about the API.
Make sure that you read the setFieldValue function too then as it contains code examples for you.
https://www.wix.com/corvid/reference/wix-dataset.Dataset.html#setFieldValue
If you are still struggling then post your code up here that you have used or tried so far and explain what you can and can’t do etc and somebody in the forum will have a look and try to help you.
Got it! Here’s what finally worked after days of frustration- and thanks for your input.
$w.onReady( () => {
$w(‘#inpGrowHardy’).value=“30”;
$w(‘#dataset1’).setFieldValue(“growingHardy”, $w(‘#inpGrowHardy’).value);
});
No thanks for me, you did it all yourself.
Glad it is now working for you.