-
-
Notifications
You must be signed in to change notification settings - Fork 197
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow project owners to add questions with a pre set list of options which can be selected when extracting information from requests. There are also options to allow blank value or multiple values, these effect how the form select input is rendered in the extracting sidebar. Fixes #8117
- Loading branch information
Showing
12 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
app/javascript/controllers/projects/key_set/select_controller.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { Controller } from "@hotwired/stimulus"; | ||
import { streamUpdate } from "helpers/stream_update"; | ||
|
||
export default class extends Controller { | ||
static targets = ["newInput"]; | ||
static values = { name: String }; | ||
|
||
addOption(event) { | ||
event.preventDefault(); | ||
|
||
const newValue = this.newInputTarget.value; | ||
if (!newValue) return; | ||
|
||
const form = this.element.closest("form"); | ||
const hiddenInput = document.createElement("input"); | ||
|
||
hiddenInput.type = "hidden"; | ||
hiddenInput.name = this.nameValue; | ||
hiddenInput.value = newValue; | ||
form.appendChild(hiddenInput); | ||
|
||
streamUpdate(form); | ||
} | ||
|
||
removeOption(event) { | ||
event.preventDefault(); | ||
|
||
const li = event.target.closest("li"); | ||
if (li) li.remove(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<%= form.fields_for :options, key.options do |f| %> | ||
<div class="project-key-set__key__value"> | ||
<%= f.label :select_allow_blank do %> | ||
<%= f.check_box :select_allow_blank, checked: key.select_allow_blank?, autocomplete: 'off' %> | ||
<%= _('Allow blank') %> | ||
<% end %> | ||
</div> | ||
|
||
<div class="project-key-set__key__value"> | ||
<%= f.label :select_allow_muliple do %> | ||
<%= f.check_box :select_allow_muliple, checked: key.select_allow_muliple?, autocomplete: 'off' %> | ||
<%= _('Allow muliple') %> | ||
<% end %> | ||
</div> | ||
|
||
<%= content_tag(:div, class: "project-key-set__key__value", data: { | ||
controller: "projects--key-set--select", | ||
projects__key_set__select_name_value: "#{f.object_name}[select_options][]" | ||
}) do %> | ||
<%= f.label :select_options, _('Options') %> | ||
<ul> | ||
<% key.select_options.each_with_index do |option, index| %> | ||
<li> | ||
<%= option %> | ||
<%= hidden_field_tag "#{f.object_name}[select_options][]", option %> | ||
<%= button_tag class: 'button-unstyled', data: { action: 'click->projects--key-set--select#removeOption' } do %> | ||
<%= _('Remove') %> | ||
<% end %> | ||
</li> | ||
<% end %> | ||
</ul> | ||
<div class="row collapse postfix-radius"> | ||
<div class="small-10 columns"> | ||
<%= text_field_tag "select_option", nil, data: { projects__key_set__select_target: 'newInput' } %> | ||
</div> | ||
<div class="small-2 columns"> | ||
<%= button_tag _('Add'), class: 'button-tertiary postfix', data: { action: 'click->projects--key-set--select#addOption' } %> | ||
</div> | ||
</div> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<div class="dataset-key"> | ||
<%= f.label :value, key.title %> | ||
<%= f.select :value, key.select_options, { include_blank: key.select_allow_blank? }, multiple: key.select_allow_muliple? %> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddOptionsToDatasetKey < ActiveRecord::Migration[7.0] | ||
def change | ||
add_column :dataset_keys, :options, :jsonb, default: {} | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters