TEXTO ESTATICO - copie el cocigo tal cual dicen de https://support.wix.com/en/article/corvid-tutorial-creating-a-show-more-link y sustitui, el nombre del boton con el mio (button1) y del texto con el mio (text5) pero no me funciona y me da el siguiente error TEXTO NO DEFINIDO
Av er si pueden ayudarme, les paso el codigo
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 = 40;
// read the full text and store it in the fullText variable
fullText = $w(#text5).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 the text element to be the short text
$w(#text5).text = shortText;
});
// check the contents of the text element
if ($w(#text5).text === shortText) {
// if currently displaying short text, display the full text
$w(#text5).text = fullText;
$w(#Button1).label = “Show less”;
} else {
// if currently displaying full text, display the short text
$w(#myText5).text = shortText;
$w(#Button5).label = “Show more”;
}
export function button1_click(event) {
//Add your code for this event here:
// display the full text
$w(#Text5).text = fullText;
// collapse the button
$w(#Button).collapse();
}
gracias
All forum posts need to be in english only.
Your issue is that you are simply missing code from your element id names.
Your code
$w(#Button).collapse();
Tutorial Code,
$w('#myButton').collapse();
You notice what you have missed off all of your element names in the code?
Also, make sure that you choose one option of the show more button of the show more/show less toggle and not both of them.
Code for the “Show More” Button
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 = 40;
// read the full text and store it in the fullText variable
fullText = $w("#myTextElement").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 the text element to be the short text
$w("#myTextElement").text = shortText;
});
export function mybutton_click(event, $w) { //making sure that you have added the onClick event in properties
// display the full text
$w("#myTextElement").text = fullText;
// collapse the button
$w("#myButton").collapse();
}
Code for the “Show More/Show Less” Toggle Button
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 = 40;
// read the full text and store it in the fullText variable
fullText = $w("#myTextElement").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 the text element to be the short text
$w("#myTextElement").text = shortText;
});
export function mybutton_click(event, $w) { //making sure that you have added the onClick event in properties
// check the contents of the text element
if ($w("#myTextElement").text === shortText) {
// if currently displaying short text, display the full text
$w("#myTextElement").text = fullText;
$w("#myButton").label = "Show less";
} else {
// if currently displaying full text, display the short text
$w("#myTextElement").text = shortText;
$w("#myButton").label = "Show more";
}
}
HOLA
My problem is that I don't know how to replace, in your codes
("#myTextElement")
the names of my elements, to be correct
1 - my text is called text5
2 - but when I pass the mouse it comes out as # text5
What should i put?
FURTHER
3 - I keep the quotes or delete ""
4 - I keep the brackets or delete them ()
THANK YOU
@mensaexprex
If your text has an id name of text5 then you simply need to replace the code to suit.
Do the same with your button name too.
//From tutorial//
$w("#myTextElement")
//To your element id name//
$w("#text5")