▷ Only the first repeater item updates! Help me please :(

Hello !

I have a problem, and I appeal to you because I can not find any solution.

I have a repeater which contains a block with a title and buttons. I wish I could change the title of the block in question. To do this, you must click on the modify button of the block in question. A block is displayed with a input. When I change the input and click on the save button, the block in question should update the title! Except this is not the case, if I modify any title of any block, this one modifies only on the first block of the repeater!

I do not understand, here is a video that films the problem I am having:

Here is my code below :

 $w("#repeater1").onItemReady( ($w, itemData, index) => {
 
      $w("#buttonmodify").onClick((event, $w) => {
           $w('#boxtitle').show();
      });
      
      $w("#savetitle").onClick((event, $w) => {
           let $item = $w.at(event.context);
           let newValue = $item('#inputtitLe').value;
           $item('#dataset1').setFieldValue('shortTextField', newValue);
           $w('#dataset1').save()
           .then( () => {
             $w('#boxtitle').hide();
           })
      });
      
 });

Please help me i don’t understand why it does this :frowning:

Try this and check if it works →

$w("#repeater1").onItemReady( ($item, itemData, index) => {
 
      $item("#buttonmodify").onClick((event) => {
           $item('#boxtitle').show();
      });
      
      $item("#savetitle").onClick((event) => {
           let newValue = $item('#inputtitLe').value;
           $item('#dataset1').setFieldValue('shortTextField', newValue);
           $w('#dataset1').save()
           .then(() => {
             $w('#boxtitle').hide();
             
           });
      });
      
 });

You can either use the method here →
https://www.wix.com/corvid/forum/main/comment/5f37fdb85b221800170dc9a9

Thank you very much for your help ! I did what you posted above, but it’s always the first block that is updated and not the second, I don’t understand. Do you have an idea please? I despair :frowning:

Here is the code :

$w.onReady(function () {

  $w("#repeater1").onItemReady( ($item, itemData, index) => {

    $item("#buttonmodify").onClick((event) => {
      $item('#boxtitle').show();
      $item('#inputtitle').value = $item('#text42').text;
   });

   $item("#savetitle").onClick((event) => {
      let newValue = $item('#inputtitle').value;
      $item('#dataset1').setFieldValue('shortTextField', newValue);
      $w('#dataset1').save()
      .then( () => {
        $w('#boxtitle').hide();
       })
    });
    
  });

  });

Thanks for your future reply

Try what is posted here →

https://www.wix.com/corvid/forum/main/comment/5f37fdb85b221800170dc9a9

$w.onReady(function () {
var item;
  $w("#repeater1").onItemReady( ($item, itemData, index) => {

    $item("#buttonmodify").onClick((event) => {
    var currentItem =  $w('#dataset1').getCurrentItem()._id;
    
    wixData.query("Database")    //database name
  .eq("_id", currentItem)   
  .find()
  .then( (results) => {
      item = results.items;
 
      $item('#boxtitle').show();
      $item('#inputtitle').value = $item('#text42').text;
      });
   });

   $item("#savetitle").onClick((event) => {
      var newValue = $item('#inputtitle').value;
      item.shortTextField = newValue;      //field Id
    wixData.update('Database', item)       //Database name
    .then((resuls1) => {
    $w('#dataset1').refresh();
    
    });
      
    });
    
  });

  });

Thank you so much for your response,
I have looked at your link. I tried to integrate the code mentioned above by trying to adapt it with the right identifiers

As soon as I click on my save button, my browser console shows me an error.

WDE0004: Failed to save [[object Object]] into [responsiveContactForm03].
Items must be JavaScript objects.

I am new to wix and must admit that I have no idea how to resolve this error message. Everything looks good to me in the code though … please help me

Here is the code I added:

$w.onReady(function () {

 var item;

  $w("#repeater1").onItemReady( ($item, itemData, index) => {
    $item("#buttonmodify").onClick((event) => {
    var currentItem =  $w('#dataset1').getCurrentItem()._id;
    wixData.query("responsiveContactForm03")
    .eq("_id", currentItem)   
    .find()
    .then( (results) => {
        item = results.items;
        $item('#boxtitle').show();
        $item('#inputtitle').value = $item('#text42').text;
      });
    });

    $item("#savetitle").onClick((event) => {
      item.shortTextField = $w('#inputtitle').value; 
      wixData.update('responsiveContactForm03', item)
      .then((resuls1) => {
        $w('#dataset1').refresh();
        $w('#boxtitle').hide();
        })
       .catch( (error) => {
          let errorMsg = error.message;
          let code = error.code;
          console.log(error.message);
        });  
     }); 
  });

});

Thanks for your future reply

Hi Lukas !

The code would be more like →

$w.onReady(function () {

    $w("#repeater1").onItemReady(($item, itemData, index) => {
        $item("#buttonmodify").onClick((event) => {
 var currentItem =  itemData._id;
            wixData.query("responsiveContactForm03")
                .eq("_id", currentItem)
                .find()
                .then((results) => {
 let item = results.items[0];   
  $item('#boxtitle').show();
        $item('#inputtitle').value = $item('#text42').text;   

                    $item("#savetitle").onClick((event1) => {
 let value = $w('#inputtitle').value;
                        item.good = value;
                        wixData.update('responsiveContactForm03', item)
                            .then((resuls1) => {
                                console.log("submitted");
                                $w('#dataset1').refresh();
                            })
                            .catch((error) => {
 let errorMsg = error.message;
 let code = error.code;
                                console.log(error.message);
                            });
                    });
                });
        });
    });

});

All the best !!