Thanks Yisreal! I actually found where the text string was missing in the code on Wix’s support page (https://support.wix.com/en/article/creating-an-expandable-text-box-with-a-show-more-link-using-wix-code) and added it. This is the code Wix tells people to add:
- // how many characters to include in the shortened version
2. const shortTextLength = 40;
3. // read the full text and store it in the fullText variable
4. fullText = $w(“#myTextElement”).text;
5. // // grab the number of characters defined in shortTextLength and store them in the shortText variable 6. shortText = fullText.substr(0, shortTextLength) + “…”;
7. // set the contents of the text element to be the short text
8. $w(“#myTextElement”).text = shortText;
As you can see on Line 8, it’s missing the string. It should be $w(“#myTextElement”).text === shortText;
The new problem, if anyone can help, is that - again per the instructions Wix has on the “Creating An Expandable Text Box…” - I have set the button to toggle (Show More, Show Less). The problem is that when the page opens, the Text Box is expanded when (according to the support page) it should be collapsed, with the toggled button to show the full text (Show More).
I can’t seem to make the fullText hide when the page first opens and gives the viewer the option to Show More.
This is the exact code Wix directs you to put in (for everything including the Text box, save for the correction I made above)
let fullText; // variable to hold the full text
let shortText; // variable to hold the short version of the text
$w.onReady(function () {
// how many characters to include in the shortened version
const shortTextLength = 60;
// read the full text and store it in the fullText variable
fullText = $w(“#text46”).text;
// // grab the number of characters defined in shortTextLength and store them in the shortText variable
shortText = fullText.substr(0, shortTextLength) + “…”;
// set the contents of #text46 to be the short text
$w(“#text46”).text === shortTextLength;
});
export function button8_click(event, $w) {
// if currently displaying short text, display the full text
if ($w(“#text46”).text === shortText) {
$w(“#text46”).text = fullText;
$w(“#button8”).label = “Show less”;
} else {
// if currently displaying full text, display the short text
$w(“#text46”).text = shortText;
$w(“#button8”).label = “Show more”;
}
}