рони,
Здравствуйте, можете подсказать как можно переписать код что бы он работал когда я нажимаю на кнопку 'add categories'
вот сам код
script
| var sel = $('.js-category-select'),
opt = $('option:not(:first-child)', sel);
function review(){
var chosen = sel.map(function(i, el){
return $(':selected',el);
});
var category = 0;
opt.show().prop('disabled', false);
chosen.each(function(i, el){
category = $(el).val();
opt.not(el).filter(function(){
return $(this).val() == category;
}).hide().prop('disabled', true);
});
}
sel.on('change', review)
вот кнопка
<fieldset id="categories_projects"><a class="btn btn-primary dropdown-toggle add_fields" data-association="categories_project" data-associations="categories_projects" data-association-insertion-template="<div class="nested-fields"><div class="field"><div class="form-group"><label class="control-label" for="project_categories_projects_attributes_new_categories_projects_category_id">Category</label><select class="form-control js-category-select" name="project[categories_projects_attributes][new_categories_projects][category_id]" id="project_categories_projects_attributes_new_categories_projects_category_id"><option value="">Select Category</option>
<option data-default_external_rate="0" value="5">Management</option>
<option data-default_external_rate="0" value="7">DevOps</option>
<option data-default_external_rate="0" value="8">Design</option>
<option data-default_external_rate="111" value="6">RoR Developer</option></select></div><div class="form-group"><label class="control-label" for="project_categories_projects_attributes_new_categories_projects_external_rate">Default External Rate</label><input class="form-control js-external_rate" type="text" name="project[categories_projects_attributes][new_categories_projects][external_rate]" id="project_categories_projects_attributes_new_categories_projects_external_rate" /></div><input type="hidden" name="project[categories_projects_attributes][new_categories_projects][_destroy]" id="project_categories_projects_attributes_new_categories_projects__destroy" value="false" /><a class="btn btn-primary remove_fields dynamic" href="#">Remove Categories</a></div></div><script>$('.js-category-select').on('change', function(e) {
var optionSelected = $("option:selected", this).data('default_external_rate');
$(this).closest('.field').find('.js-external_rate').val(optionSelected)
});</script><script>var sel = $('.js-category-select'),
opt = $('option:not(:first-child)', sel);
function review(){
var chosen = sel.map(function(i, el){
return $(':selected',el);
});
var category = 0;
opt.show().prop('disabled', false);
chosen.each(function(i, el){
category = $(el).val();
opt.not(el).filter(function(){
return $(this).val() == category;
}).hide().prop('disabled', true);
});
}
sel.on('change', review)</script>" href="#">add categories</a></fieldset>