Skip to content

Commit

Permalink
Fix the select2 in the controlled vocab modal
Browse files Browse the repository at this point in the history
  • Loading branch information
stuzart committed Jan 25, 2024
1 parent b657e2b commit 1cae556
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/assets/javascripts/controlled_vocabs.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,20 @@ var SampleTypeControlledVocab = {
initialise_rich_text_editors(".rich-text-edit");
},

copyBlankModalForm: function() {
// first destroy any select2 elements, which won't survive being cloned. They will be initialised again when reset
$j('#cv-modal select[data-role="seek-objectsinput"]').select2('destroy');
SampleTypeControlledVocab.blankControlledVocabModelForm=$j('#cv-modal').clone();
},

//resets the modal
resetModalControlledVocabForm: function () {
$j('#cv-modal').remove();
$j('#modal-dialogues').append(SampleTypeControlledVocab.blankControlledVocabModelForm.clone());
CVTerms.init();
ObjectsInput.init();
SampleTypeControlledVocab.bindNewControlledVocabShowEvent();
SampleTypeControlledVocab.initialise_deferred_rich_editor_modal();

},

//selected CV item changed
Expand Down
2 changes: 1 addition & 1 deletion app/views/isa_studies/_sample_types_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<script>
//used to hold the element Id that needs updating after creating a new CV
$j(document).ready(function () {
SampleTypeControlledVocab.blankControlledVocabModelForm=$j('#cv-modal').clone();
SampleTypeControlledVocab.copyBlankModalForm();
SampleTypeControlledVocab.resetModalControlledVocabForm();
// Make rows sortable
SampleTypes.bindSortable("#<%=attribute_table_id%>");
Expand Down
2 changes: 1 addition & 1 deletion app/views/sample_types/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@
<script>
//used to hold the element Id that needs updating after creating a new CV
$j(document).ready(function () {
SampleTypeControlledVocab.blankControlledVocabModelForm=$j('#cv-modal').clone();
SampleTypeControlledVocab.copyBlankModalForm();
SampleTypeControlledVocab.resetModalControlledVocabForm();
// Make rows sortable
SampleTypes.bindSortable();
Expand Down
2 changes: 1 addition & 1 deletion app/views/templates/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
<script>
//used to hold the element Id that needs updating after creating a new CV
$j(document).ready(function() {
SampleTypeControlledVocab.blankControlledVocabModelForm = $j('#cv-modal').clone();
SampleTypeControlledVocab.copyBlankModalForm();
SampleTypeControlledVocab.resetModalControlledVocabForm();
//Make rows sortable
SampleTypes.bindSortable();
Expand Down

0 comments on commit 1cae556

Please sign in to comment.