Skip to content

Commit

Permalink
Add hidden id fields to the CV terms form and add a uniqueness clause…
Browse files Browse the repository at this point in the history
… to the validation
  • Loading branch information
kdp-cloud committed May 31, 2024
1 parent 580f342 commit d143bd4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/sample_controlled_vocab_term.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class SampleControlledVocabTerm < ApplicationRecord
belongs_to :sample_controlled_vocab, inverse_of: :sample_controlled_vocab_terms

validates :label, presence: true, length: { maximum: 500 }
validates :label, presence: true, length: { maximum: 500 }, uniqueness: { scope: :sample_controlled_vocab_id }

before_validation :truncate_label

Expand Down
5 changes: 4 additions & 1 deletion app/views/sample_controlled_vocabs/_term_form_row.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
<tr class="sample-cv-term" data-index="<%= index %>">
<td><%= text_field_tag "sample_controlled_vocab[sample_controlled_vocab_terms_attributes][#{index}][label]", term.label %></td>
<td>
<%= hidden_field_tag "sample_controlled_vocab[sample_controlled_vocab_terms_attributes][#{index}][id]", term.id %>
<%= text_field_tag "sample_controlled_vocab[sample_controlled_vocab_terms_attributes][#{index}][label]", term.label %>
</td>
<td><%= text_field_tag "sample_controlled_vocab[sample_controlled_vocab_terms_attributes][#{index}][iri]", term.iri %></td>
<td><%= text_field_tag "sample_controlled_vocab[sample_controlled_vocab_terms_attributes][#{index}][parent_iri]", term.parent_iri %></td>
<td>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
%>
<tr class="<%= row_class %>" data-index="<%= index %>">
<td>
<%= hidden_field_tag "sample_controlled_vocab[sample_controlled_vocab_terms_attributes][#{index}][id]", term.id %>
<%= hidden_field_tag "sample_controlled_vocab[sample_controlled_vocab_terms_attributes][#{index}][label]", term.label %>
<div class='disabled-cv-field form-control'><%= term.label %></div>
</td>
Expand Down

0 comments on commit d143bd4

Please sign in to comment.