Answer the question
In order to leave comments, you need to log in
How to add new object to jquery array after ajax insert?
The rails app page has a form with a set of checkboxes that act like radio buttons. The script looks like this:
window.$covers_set = $('#building_views').find("input[id$='is_cover']")
$covers_set.click( ->
$covers_set.not(this).removeAttr('checked')
)
$covers_set
? # rails хелпер
= javascript_tag "$covers_set.add($('#тут_id_нового_чек-бокса'));"
Answer the question
In order to leave comments, you need to log in
$('#building_views').on("click", "input[id$='is_cover']", function(){
$covers_set.not(this).removeAttr('checked');
});
I support the @itspers
option .
I don't know how things are with on, but in the past, using live was considered not the best practice. Alternative is to update $coversSet onSuccess ajax. Those. something like this:
var $coversSet = $('#building_views').find("input[id$='is_cover']");
$.ajax({
// url, data, type, etc
success : function(result) {
$coversSet = $('#building_views').find("input[id$='is_cover']");
}
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question