I have put a solution to this behaviour at the bottom of the page.
Code for this page:
import wixWindowFrontend from 'wix-window-frontend';
let myText = "This is an example text in a textbox. It is linked to a variable. As it is loaded through code it seems that you cannot save it or 'get' it unless you have edited the text in the box first";
let myText2 = "This is an example text in a text input. It is linked to a variable, but unlike the textbox example on the left, you can use the 'get' function without editing the text first"
$w.onReady(async function () {
if (wixWindowFrontend.rendering.env === "browser") {
$w('#myTextBox').value = myText;
$w('#myTextInput').value = myText2;
}
});
$w('#saveTextBoxValue').onClick((event) => {
let myValue = $w('#myTextBox').value;
$w('#textBoxOutput').text = myValue;
})
$w('#saveTextInputValue').onClick((event) => {
let myValue = $w('#myTextInput').value;
$w('#textInputOutput').text = myValue;
})
This shows the proposed solution - make sure the textBox isn't contained within the rendering API - not a particularly satisfactory solution but the best you can do with an increasingly glitchy Wix backbone. My thanks to the Wix helpdesk for pointing me in this direction.
TextBox example:
The text from the box above $w('#myTextBoxSolved') should appear below in $w('#textBoxOutputSolved') when you click the save button
text should appear here...
Text Input example:
The text from the box above should appear below in $w('#textInputOutputSolved') when you click the save button
text should appear here...
Code with proposed solution
import wixWindowFrontend from 'wix-window-frontend';
let myText = "This is an example text in a textbox. It is linked to a variable. As it is loaded through code it seems that you cannot save it or 'get' it unless you have edited the text in the box first";
let myText2 = "This is an example text in a text input. It is linked to a variable, but unlike the textbox example on the left, you can use the 'get' function without editing the text first"
$w.onReady(async function () {
if (wixWindowFrontend.rendering.env === "browser") {
$w('#myTextBox').value = myText;
$w('#myTextInput').value = myText2;
} // End rendering API here
//Solution
$w('#myTextBoxSolved').value = myText;
$w('#myTextInputSolved').value = myText2;
});
$w('#saveTextBoxValue').onClick((event) => {
let myValue = $w('#myTextBox').value;
$w('#textBoxOutput').text = myValue;
})
$w('#saveTextInputValue').onClick((event) => {
let myValue = $w('#myTextInput').value;
$w('#textInputOutput').text = myValue;
})
// proposed solution
$w('#saveTextBoxValueSolved').onClick((event) => {
let myValue = $w('#myTextBoxSolved').value;
$w('#textBoxOutputSolved').text = myValue;
})
$w('#saveTextInputValueSolved').onClick((event) => {
let myValue = $w('#myTextInputSolved').value;
$w('#textInputOutputSolved').text = myValue;
})
$w('#button1').onClick((event) => {
$w('#solvedSection').expand();
})