Hi,
I have a button in a repeater which connected to a database of “Samsung smartphones”.
What I need is to hide the name “Samsung” in the buttons, so that it only shows the model name, e.g ( “Samsung Galaxy C7” – shows only → “Galaxy C7” )
If you always want to hide the first word only, you can add this code:
$w.onReady(() => {
$w("#repeater1").onItemReady(($i, iData, inx) => {
let text = $i("#text1").text.split(" ");
text.shift();
text.join(" ");
$i("#text1").text = text;//instead of text1 use your text id
})
})
(fixed)
I’ve just tried it but the first word “samsung” still visible, I changed the #text1 to #button6 , because the text appears in the button. Do you know what could have gone wrong ?
@stborz it’s a button not a text, so replace all the “text” properties in the code, and use “label” instead.
@stborz Let’s do it like that:
$w.onReady(() => {
$w("#repeater1").onItemReady(($i, iData, inx) => {
let label = $i("#button6").label.split(" ");
label.shift();
label.join(" ");
$i("#button6").label = label;
})
})
(fixed)
@jonatandor35 after spending so much time using your last code I found the issue but not the solution. Maybe you could help out once again ?!
The issue is that the code happens before onItemReady, because when I debugged consol.log() I found that the label is not from the dataset, its just the “text” which is there before connecting to dataset , take a look at the pictures attached here
DEV MODE -------------------------------
PREVIEV MODE -------------------------------
@stborz OK. I thought you connected the button to the relevant dataset field via the editor.
So there’re 2 options:
- to connect it to the dataset and then use my last code. OR:
- to use the field key instead. Something like:
$w.onReady(() => {
$w("#repeater1").onItemReady(($i, iData, inx) => {
let label = iData.model.split(" ");//instead of model, use your collection field key
label.shift();
label.join(" ");
$i("#button6").label = label;
})
})
I didn’t see the above replies because the forum only loads replies when it feels like it. Anyway…
$w.onReady(() =>
{
$w('#dataset1').onReady(() =>
{
$w('#repeater1').onItemReady($item =>
{
$item('#button1').label = $item('#button1').label.replace(/^Samsung /, '');
});
});
});
This one fixed it !!! Perfect
thanx for both of you for your will to help