Commit 4c19c48b authored by Michael Rose's avatar Michael Rose

shipsearch: fix character changes when fandom changes

parent 82cd6365
......@@ -186,27 +186,47 @@ window.init = function() {
if (params.length > 0) {
return $.getJSON(`/characters?${params.join('&')}`, function(data) {
const select = $("[name='search[character_required][]']");
const select2 = $("[name='search[character_optional][]']");
// const select = $("[name='search[character_required][]']");
// const select2 = $("[name='search[character_optional][]']");
//
// const existing = select.val();
// const existing2 = select2.val();
//
// const options = select.prop('options');
// const options2 = select2.prop('options');
// $('option', select).remove();
// $('option', select2).remove();
console.log($('.character_list').toArray());
for (let select of $('.character_list').toArray()) {
select = $(select);
let existing = select.val();
const existing = select.val();
const existing2 = select2.val();
const options = select.prop('options');
$('option', select).remove();
$.each(data, function(k,v) {
options[options.length] = new Option(v.name,v.id);
});
const options = select.prop('options');
const options2 = select2.prop('options');
$('option', select).remove();
$('option', select2).remove();
select.val(existing);
select.trigger('chosen:updated');
}
let selectTemplate = $('#shiprow-template select');
const options = selectTemplate.prop('options');
$('option', selectTemplate).remove();
$.each(data, function(k,v) {
options[options.length] = new Option(v.name,v.id);
return options2[options.length] = new Option(v.name,v.id);
});
select.val(existing);
select2.val(existing2);
select.trigger('chosen:updated');
return select2.trigger('chosen:updated');
//
//
//
// select.val(existing);
// select2.val(existing2);
//
// select.trigger('chosen:updated');
// return select2.trigger('chosen:updated');
});
} else {
return $.Deferred().resolveWith({});
......@@ -316,6 +336,7 @@ function clone_relationship_row() {
const select = new_row.find('select');
select.attr('name', 'search[relationships][' + next_index + '][characters][]');
select.attr('id', 'search[relationships][' + next_index + '][characters][]');
select.addClass('character_list');
const button = new_row.find('button');
button.attr('id', 'remove_relationships[' + next_index + ']');
button.attr('name', 'remove_relationships[' + next_index + ']');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment