Hi, I would like to know if this is possible.
What I want to try is replacing a specific word in a repeater based on the user’s input.
For example, if I have the following user input and a repeater with three items:
User input: Jade
My repeater’s repeating paragraph:
item 1: [text1 text1 text1 {NAME} text1 text1]
item 2: [text2 {NAME} text2 text2 text2 text2]
item 3: [{NAME} text3 text3 text3 text3]
Please notice {NAME}s are placed in a different part of the paragraphs. I would like to do global replace of {NAME} to Jade for all items in the repeater.
My items are connected to a database.
Would this be possible? Thanks!
I already know about that commend. My issue is that it is a repeater. If that commend can still be used, i need help on how to use it in the repeater. Thanks!
jamie
July 17, 2018, 1:36pm
4
Sorry, I may not be understanding your question correctly, but could you iterate the repeater and do a replace, say like;
$w("#dataset").onReady(() => {
$w("#repeater1").forEachItem(($w, itemData, index) => {
const name = $w("#input").value;
$w("#textItem").text.replace(/{NAME}/i, name);
});
});
This is untested, but once your dataset has loaded you itterate the repeater and replace any instance of ‘{NAME}’ in the text item with the value from the input.
Check out https://www.wix.com/code/reference/$w.Repeater.html#repeated-item-scope for some help on working with repeaters in wixcode
Jamie! Thank you!! I’m away from my keyboard right now, but i will for sure test that later today
I finally made a time to try today, and I’ve resolved it!! Thanks a lot. I struggled a little but was able to figure out.
Did this ever get definitively resolved. I am trying the same thing but don’t see the replacement happening within the repeater.
$w . onReady ( function () {
$w ( “#dataset11 ” ). onReady (() => {
$w ( "#repeater1" ). onItemReady ( ( $item , itemData , index ) => {
$w ( “#repeater1 ” ). forEachItem (( $w , itemData , index ) => {
**const** name = $w ( '#dynamicDataset' ). getCurrentItem (). title ;
console . log ( "name is" , name );
$w ( "#text132" ). text . replace ( /(Student's Name)/ **g** , name );
$w ( "#text132" ). text . replace ( "story" , "elephant" );
console . log ( "replacement text is" , $w ( "#text132" ). text );
});
});
});
});