I followed the directions here: https://support.wix.com/en/article/creating-an-expandable-text-box-with-a-show-more-link-using-wix-code
For creating an exandable textbox.
However; get an error " the element selector function (usually $w) cannot be used before the page is ready.
import wixData from ‘wix-data’;
let fullText; // variable to hold the full text
let shortText; // variable to hold the short version of the text
$w(“FormEnterRP”).onCurrentIndexChanged( function () { //<-- throws error .
// how many characters to include in the shortened version
const shortTextLength = 40;
// set the fullText variable to be the text from the collection
fullText = $w(‘#FormEnterRP’).getCurrentItem().begin; //<-- read current value in database
// if no text to display, collapse the text element and the button
if (!fullText) {
$w(‘#myTextElement’).collapse();
$w(‘#myButton’).collapse();
} else {
// if the text has fewer or the same number of characters as shortTextLength characters, display it as is and collapse the “Show More” button
if (fullText.length <= shortTextLength) {
$w(‘#myTextElement’).text = fullText;
$w(‘#myButton’).collapse();
} else {
// create the shortened version of the text and display it in the text element
shortText = fullText.substr(0, shortTextLength) + “…”;
$w(‘#myTextElement’).text = shortText;
}
}
});
export function myButton_mouseIn(event, $w) {
//Add your code for this event here:
// display the full text
$w(“#myTextElement”).text = fullText;
// collapse the button
$w(“#myButton”).collapse();
}
I am open to any suggestions for how to fill a dynamic page with output from user input, and from a database query I am open to suggestions.