-
Notifications
You must be signed in to change notification settings - Fork 191
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
initialize repeater with multiple repeats? #46
Comments
The library allows for more than one item to be rendered initially in the html markup, like this <form class="repeater">
<div data-repeater-list="group-a">
<div data-repeater-item>
<input type="text" name="text-input" value="A"/>
<input data-repeater-delete type="button" value="Delete"/>
</div>
<div data-repeater-item>
<input type="text" name="text-input" value="B"/>
<input data-repeater-delete type="button" value="Delete"/>
</div>
</div>
<input data-repeater-create type="button" value="Add"/>
</form> The library also has an option to set the list items programattically, like this var $repeater = $('.repeater').repeater();
$repeater.setList([
{ 'text-input': 'A' },
{ 'text-input': 'B' }
]); |
Hello @DubFriend, I am trying to achieve a similar result programatically using repeaterVal to grab the form values and then serializing into JSON where I can then save to my database. The logical method to then re-display the form values is to use setList, however, I can't quite get it to work using the JSON string I've grabbed via repeaterVal. Could you provide any insight into this? Here's some sample code:
I'm trying to avoid manually re-entering each of the form values. According to your setList documentation something like this should work but I am having trouble. Thank you for your time. |
I managed to get my problem solved and I'm posting a solution here in-case anyone else happens to try and solve a similar issue. My intended use case is to save my form data and to later be able to re-display the repeated form inputs using my saved data. So for example if you had a grocery list and wanted to save the list and then later re-edit the list to add or delete items. The operations are broken down into 2 functions. One to save the form data and the other to re-display the data using repeaterVal and setList respectively.
To recap: Save form data
Set form data
|
maparaschivei, thank you for your solution to this, it helped me out. |
can you please let me know how to save that data in database??? |
@ShayanShams What are you using for your back-end? PHP, Python, .NET, etc. I can help point you in the right direction if I know what you're working with. |
I have this same issue, in my case tho I'm using select instead of text input, does the setList() method have a overload so that I can populate my select element inside my repeater with pre-existing data? |
Hi I am using jquery.repeater in accordion along with cf7 forms but it's not working though no errors are fired as i checked in console also.. Can you help me with this ??? |
@rdlandim populating select fields works fine for me. You need to pass it the value attribute of the select field though, not the option value.
|
@robfrancken my problem was a little more complicated cause I were using select2 plugin instead of simple select input so just initializing the html with the values were not working properly, what I did was iterate through my list of select2 inputs and render then only with the selected option, the rest worked as usual |
Thanks @maparaschivei, How about setList for nested repeaters? I can't set the nested repeaters! :( |
Thanks for the solution and its works but; What for multiple groups like group-a, group-b, and so on.
If i am using same solution for multiple group then its not working for setList. Thanks. |
i am facing the same issue, how can i initialize the form repeater with multiple set values? |
@maparaschivei can you please give me an example how to add and edit data with .NET backend |
I have also a problem from multi array repeaters. How can i achieve this array on repeater.
|
I'm utilizing your plugin right now and upon form submit, it checks form validation. If the form is invalid, it returns to the page and shows the errors. I wanted to ask, if the user uses the repeater and repeats the item 5 times, is there a function available where I can just have the repeater repeat the item 5 times on load so I can just fill in the old data in the proper spots?
The text was updated successfully, but these errors were encountered: