Skip to content
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

Repeater for Labels #40

Closed
bob-zs opened this issue Nov 28, 2016 · 7 comments
Closed

Repeater for Labels #40

bob-zs opened this issue Nov 28, 2016 · 7 comments

Comments

@bob-zs
Copy link

bob-zs commented Nov 28, 2016

Is there a way for the repeater to also repeat labels with their corresponding checkboxes?

<input type="checkbox" id="myCheckbox[0]"><label for="myCheckbox[0]"></label>

repeated to

<input type="checkbox" id="myCheckbox[1]"><label for="myCheckbox[1]"></label>
@DubFriend
Copy link
Owner

you could use a custom "show" callback to do this, something like this?

$('.my-repeater').repeater({
  show: function () {
    $(this).find('label').attr('for', $(this).find('input').attr('id'));
    $(this).show();
  }
})

@juancarlosestradanieto
Copy link

Hi, I just made this, I hope it can help anybody.
This plugin is very helpful. Thanks.
`
$('.my-repeater').repeater({
show: function () {

//fixing the issue of the labels
var params = [this];
$(this).find("label[for]").each(function(index, element) {
	var currentRepeater = params[0];
	var originalFieldId = $(element).attr("for");
	var newField = $(currentRepeater).find("input[id='"+originalFieldId+"']");
	if($(newField).length > 0)
	{
		var newFieldName = $(newField).attr('name');
		$(newField).attr('id', newFieldName);
		$(currentRepeater).find("label[for='"+originalFieldId+"']").attr('for', newFieldName);
	}
},params);					

//showing the new repeater
$(this).slideDown();

$(this).show();

}
})
`

@martinmurciego
Copy link

martinmurciego commented Sep 14, 2018

Re-Styling with Markdown only:

$('.my-repeater').repeater({
show: function () {

//fixing the issue of the labels
var params = [this];
$(this).find("label[for]").each(function(index, element) {
	var currentRepeater = params[0];
	var originalFieldId = $(element).attr("for");
	var newField = $(currentRepeater).find("input[id='"+originalFieldId+"']");
	if($(newField).length > 0)
	{
		var newFieldName = $(newField).attr('name');
		$(newField).attr('id', newFieldName);
		$(currentRepeater).find("label[for='"+originalFieldId+"']").attr('for', newFieldName);
	}
},params);					

//showing the new repeater
$(this).slideDown();

$(this).show();
}
})

@helloKeyur
Copy link

ou could use a custom "show" callback to do this, something like this?

How I can set my ID attribute in input box ??

@helloKeyur
Copy link

Is there a way for the repeater to also repeat labels with their corresponding checkboxes?

<input type="checkbox" id="myCheckbox[0]"><label for="myCheckbox[0]"></label>

repeated to

<input type="checkbox" id="myCheckbox[1]"><label for="myCheckbox[1]"></label>

hello @bob-zs please help me
How I can increase my input ID Attribute using this formRepeater plugin?

@cawecoy
Copy link

cawecoy commented Apr 16, 2021

@DubFriend thanks. What if some item is deleted and then the list gets reordered?

@DubFriend
Copy link
Owner

DubFriend commented Apr 16, 2021 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants