1

Hi I have a form that implements jquery-repeater. Code was working fine and somehow it has stopped functioning properly. Basically I have 2 different pages 1 for new form 2nd for editing a form. On new form everything works fine but edit fails.

New Form

Edit Form

For the first button my default text is "Firma Seç" after clicking the "+" button I am executing code below:

iter_sales++; //holds the row count
var seller_btn = $('[name^="group-a"][name$="[seller_button]"]')[iter_sales-1]; //get new button object
seller_btn.innerText = "Firma Seç" // change inner text to default

Same code works for the new-form but on edit-form row is not being created and object returns null due to inbound array index.

Error : Uncaught TypeError: Cannot set properties of undefined (setting 'innerText')

I tried couple of things like sleeping the function wait for row to be created but didn't work. And same code was working before.

EDIT:

Button element:

<button id="maliyet_firma_modal_btn" name="group-a[seller_button]"
                                                    style="width: 120px!important;
min-width: 120px;
max-width: 120px;
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;" onClick="get_firma(this)" type="button"
                                                    class="btn btn-primary save-button" data-toggle="modal"
                                                    data-target="#demoModal">Firma Seç
                                            </button>
seneill
  • 63
  • 7
  • Please show us the object that `$('[name^="group-a"][name$="[seller_button]"]')` refers to – Carsten Løvbo Andersen Apr 29 '22 at 12:06
  • Sorry I have rushed a bit, edited as requested. – seneill Apr 29 '22 at 12:08
  • I would try and do `console.log($('[name^="group-a"][name$="[seller_button]"]').length)`, and `console.log(iter_sales)` to see those values. To me it sounds like `iter_sales` is higher than the amount of buttons that exist. aka why its undefined – Carsten Løvbo Andersen Apr 29 '22 at 12:10
  • I have tried those after repeater appending the row all seems fine but here are the results. I have edited an entity with 2 rows object length returned 2 and iterator returned 2, then i have disabled innertext modification and added another row, object length was 3 and iterator was 3 too – seneill Apr 29 '22 at 12:14
  • From the code you have provided I can see that it works, so without being able to reproduce the problem you are facing then we can't do much. – Carsten Løvbo Andersen Apr 29 '22 at 12:18
  • Incremental and selecting the object works but it seems repeater somehow waits for my function to finish to append the row and I need repeater to append it before the function .var seller_btn = $('[name^="group-a"][name$="[seller_button]"]')[iter_sales-1]; seller_btn.innerText = "Firma Seç" if i add these two lines code is breaking because selector needs repeater to append first. – seneill Apr 29 '22 at 12:21
  • @CarstenLøvboAndersen I have fixed but no idea how I did it, so the button text changes according if you click it and select a seller from the pop-up button changes as selected seller name, and there is also another hidden input "seller_id" also gets the selected value. What I did was imported the repeater code to local file from external js file and added: defaultValues: { 'seller_id': '', } to repeater init function and now somehow it works, do you think this should be posted as answer ? – seneill Apr 29 '22 at 13:23

0 Answers0