add radio and checkboxes steps
This commit is contained in:
@@ -41,7 +41,7 @@
|
|||||||
v-for="(area, index) in areas"
|
v-for="(area, index) in areas"
|
||||||
:key="index"
|
:key="index"
|
||||||
>
|
>
|
||||||
{{ area }}
|
Area {{ index + 1 }}
|
||||||
<button @click="removeArea(area)">
|
<button @click="removeArea(area)">
|
||||||
×
|
×
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ import { actionable } from '@github/catalyst/lib/actionable'
|
|||||||
export default actionable(targetable(class extends HTMLElement {
|
export default actionable(targetable(class extends HTMLElement {
|
||||||
static [target.static] = [
|
static [target.static] = [
|
||||||
'form',
|
'form',
|
||||||
'completed',
|
'completed'
|
||||||
'submitButton'
|
|
||||||
]
|
]
|
||||||
|
|
||||||
static [targets.static] = [
|
static [targets.static] = [
|
||||||
@@ -22,16 +21,28 @@ export default actionable(targetable(class extends HTMLElement {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
submitSignature () {
|
|
||||||
this.submitButton.click()
|
|
||||||
}
|
|
||||||
|
|
||||||
setVisibleStep (uuid) {
|
setVisibleStep (uuid) {
|
||||||
this.steps.forEach((step) => {
|
this.steps.forEach((step) => {
|
||||||
step.classList.toggle('hidden', step.dataset.fieldUuid !== uuid)
|
step.classList.toggle('hidden', step.dataset.fieldUuid !== uuid)
|
||||||
})
|
})
|
||||||
|
|
||||||
this.fields.find(f => f.id === uuid).focus()
|
this.fields.find(f => f.id === uuid)?.focus()
|
||||||
|
}
|
||||||
|
|
||||||
|
submitSignature (e) {
|
||||||
|
e.target.okButton.disabled = true
|
||||||
|
|
||||||
|
fetch(this.form.action, {
|
||||||
|
method: this.form.method,
|
||||||
|
body: new FormData(this.form)
|
||||||
|
}).then(response => {
|
||||||
|
console.log('Form submitted successfully!', response)
|
||||||
|
this.moveNextStep()
|
||||||
|
}).catch(error => {
|
||||||
|
console.error('Error submitting form:', error)
|
||||||
|
}).finally(() => {
|
||||||
|
e.target.okButton.disabled = false
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
submitForm (e) {
|
submitForm (e) {
|
||||||
|
|||||||
@@ -7,7 +7,9 @@ import { DirectUpload } from '@rails/activestorage'
|
|||||||
export default actionable(targetable(class extends HTMLElement {
|
export default actionable(targetable(class extends HTMLElement {
|
||||||
static [target.static] = [
|
static [target.static] = [
|
||||||
'canvas',
|
'canvas',
|
||||||
'input'
|
'input',
|
||||||
|
'okButton',
|
||||||
|
'clearButton'
|
||||||
]
|
]
|
||||||
|
|
||||||
connectedCallback () {
|
connectedCallback () {
|
||||||
@@ -17,6 +19,8 @@ export default actionable(targetable(class extends HTMLElement {
|
|||||||
submit (e) {
|
submit (e) {
|
||||||
e?.preventDefault()
|
e?.preventDefault()
|
||||||
|
|
||||||
|
this.okButton.disabled = true
|
||||||
|
|
||||||
this.canvas.toBlob((blob) => {
|
this.canvas.toBlob((blob) => {
|
||||||
const file = new File([blob], 'signature.jpg', { type: 'image/jpg' })
|
const file = new File([blob], 'signature.jpg', { type: 'image/jpg' })
|
||||||
|
|
||||||
|
|||||||
@@ -21,18 +21,25 @@
|
|||||||
<% visible_step_index = nil %>
|
<% visible_step_index = nil %>
|
||||||
<% @submission.flow.fields.each_with_index do |field, index| %>
|
<% @submission.flow.fields.each_with_index do |field, index| %>
|
||||||
<% visible_step_index ||= index if @submission.values[field['uuid']].blank? %>
|
<% visible_step_index ||= index if @submission.values[field['uuid']].blank? %>
|
||||||
<disable-hidden data-field-uuid="<%= field['uuid'] %>" data-targets="flow-view.steps" class="block <%= 'hidden' if index != visible_step_index %>">
|
<disable-hidden data-field-type="<%= field['type'] %>" data-field-uuid="<%= field['uuid'] %>" data-targets="flow-view.steps" class="block <%= 'hidden' if index != visible_step_index %>">
|
||||||
<% if index != 0 %>
|
<% if index != 0 %>
|
||||||
<button data-action="click:flow-view#moveStepBack">
|
<button data-action="click:flow-view#moveStepBack">
|
||||||
Back
|
Back
|
||||||
</button>
|
</button>
|
||||||
<% end %>
|
<% end %>
|
||||||
<label for="<%= field['uuid'] %>"><%= field['name'].presence || 'FIeld' %></label>
|
<label for="<%= field['uuid'] %>"><%= field['name'].presence || 'FIeld' %></label>
|
||||||
|
<br>
|
||||||
<% if index == @submission.flow.fields.size - 1 %>
|
<% if index == @submission.flow.fields.size - 1 %>
|
||||||
<input type="hidden" name="completed" value="true">
|
<input type="hidden" name="completed" value="true">
|
||||||
|
<div>
|
||||||
|
<button type="submit"><%= button_title %></button>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% if field['type'].in?(['text', 'date']) %>
|
<% if field['type'].in?(['text', 'date']) %>
|
||||||
<input <%= html_attributes(required: 'true') if field['required'] %> id="<%= field['uuid'] %>" data-targets="flow-view.fields" data-action="input:flow-view#passValueToArea focus:flow-view#focusArea" value="<%= @submission.values[field['uuid']] %>" type="<%= field['type'] %>" name="values[<%= field['uuid'] %>]">
|
<input class="text-xl" <%= html_attributes(required: 'true') if field['required'] %> id="<%= field['uuid'] %>" data-targets="flow-view.fields" data-action="input:flow-view#passValueToArea focus:flow-view#focusArea" value="<%= @submission.values[field['uuid']] %>" type="<%= field['type'] %>" name="values[<%= field['uuid'] %>]">
|
||||||
|
<div>
|
||||||
|
<button type="submit"><%= button_title %></button>
|
||||||
|
</div>
|
||||||
<% elsif field['type'] == 'select' %>
|
<% elsif field['type'] == 'select' %>
|
||||||
<select <%= html_attributes(required: 'true') if field['required'] %> id="<%= field['uuid'] %>" data-targets="flow-view.fields" data-action="input:flow-view#passValueToArea focus:flow-view#focusArea" name="values[<%= field['uuid'] %>]">
|
<select <%= html_attributes(required: 'true') if field['required'] %> id="<%= field['uuid'] %>" data-targets="flow-view.fields" data-action="input:flow-view#passValueToArea focus:flow-view#focusArea" name="values[<%= field['uuid'] %>]">
|
||||||
<option value="" disabled selected>Select your option</option>
|
<option value="" disabled selected>Select your option</option>
|
||||||
@@ -40,6 +47,9 @@
|
|||||||
<option <%= html_attributes(selected: 'true') if @submission.values[field['uuid']] == option %> value="<%= option %>"><%= option %></option>
|
<option <%= html_attributes(selected: 'true') if @submission.values[field['uuid']] == option %> value="<%= option %>"><%= option %></option>
|
||||||
<% end %>
|
<% end %>
|
||||||
</select>
|
</select>
|
||||||
|
<div>
|
||||||
|
<button type="submit"><%= button_title %></button>
|
||||||
|
</div>
|
||||||
<% elsif field['type'] == 'image' || field['type'] == 'attachment' %>
|
<% elsif field['type'] == 'image' || field['type'] == 'attachment' %>
|
||||||
<br>
|
<br>
|
||||||
<files-list data-field-uuid="<%= field['uuid'] %>">
|
<files-list data-field-uuid="<%= field['uuid'] %>">
|
||||||
@@ -52,24 +62,48 @@
|
|||||||
<input multiple data-target="file-dropzone.input" data-action="change:file-dropzone#onSelectFiles" id="<%= uuid %>" type="file" class="hidden">
|
<input multiple data-target="file-dropzone.input" data-action="change:file-dropzone#onSelectFiles" id="<%= uuid %>" type="file" class="hidden">
|
||||||
</file-dropzone>
|
</file-dropzone>
|
||||||
</files-list>
|
</files-list>
|
||||||
|
<div>
|
||||||
|
<button type="submit"><%= button_title %></button>
|
||||||
|
</div>
|
||||||
<% elsif field['type'] == 'signature' %>
|
<% elsif field['type'] == 'signature' %>
|
||||||
<signature-pad data-submission-slug="<%= @submission.slug %>" data-action="upload:flow-view#submitSignature">
|
<signature-pad data-submission-slug="<%= @submission.slug %>" data-action="upload:flow-view#submitSignature">
|
||||||
<input data-target="signature-pad.input" type="hidden" name="values[<%= field['uuid'] %>]" value="<%= @submission.values[field['uuid']] %>">
|
<input data-target="signature-pad.input" type="hidden" name="values[<%= field['uuid'] %>]" value="<%= @submission.values[field['uuid']] %>">
|
||||||
<canvas data-target="signature-pad.canvas">
|
<canvas data-target="signature-pad.canvas"></canvas>
|
||||||
</canvas>
|
<button data-target="signature-pad.clearButton" data-action="click:signature-pad#clear">
|
||||||
<button data-action="click:signature-pad#submit">
|
|
||||||
Ok
|
|
||||||
</button>
|
|
||||||
<button data-action="click:signature-pad#clear">
|
|
||||||
Clear
|
Clear
|
||||||
</button>
|
</button>
|
||||||
|
<br>
|
||||||
|
<button data-target="signature-pad.okButton" data-action="click:signature-pad#submit">
|
||||||
|
<%= button_title %>
|
||||||
|
</button>
|
||||||
</signature-pad>
|
</signature-pad>
|
||||||
<% elsif field['type'] == 'radio' %>
|
<% elsif field['type'] == 'radio' %>
|
||||||
|
<% field['options'].each do |option| %>
|
||||||
|
<div>
|
||||||
|
<input <%= html_attributes(checked: true) if @submission.values[field['uuid']] == option %> id="<%= field['uuid'] + option %>" type="radio" name="values[<%= field['uuid'] %>]" value="<%= option %>">
|
||||||
|
<label for="<%= field['uuid'] + option %>">
|
||||||
|
<%= option %>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<div>
|
||||||
|
<button type="submit"><%= button_title %></button>
|
||||||
|
</div>
|
||||||
<% elsif field['type'] == 'checkbox' %>
|
<% elsif field['type'] == 'checkbox' %>
|
||||||
|
<% field['options'].each do |option| %>
|
||||||
|
<div>
|
||||||
|
<input <%= html_attributes(checked: true) if @submission.values[field['uuid']]&.include?(option) %> id="<%= field['uuid'] + option %>" type="checkbox" name="values[<%= field['uuid'] %>]" value="<%= option %>">
|
||||||
|
<label for="<%= field['uuid'] + option %>">
|
||||||
|
<%= option %>
|
||||||
|
</label>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<div>
|
||||||
|
<button type="submit"><%= button_title %></button>
|
||||||
|
</div>
|
||||||
<% end %>
|
<% end %>
|
||||||
</disable-hidden>
|
</disable-hidden>
|
||||||
<% end %>
|
<% end %>
|
||||||
<button data-target="flow-view.submitButton" type="submit"><%= button_title %></button>
|
|
||||||
</form>
|
</form>
|
||||||
<div data-target="flow-view.completed" class="hidden">
|
<div data-target="flow-view.completed" class="hidden">
|
||||||
<p>
|
<p>
|
||||||
|
|||||||
Reference in New Issue
Block a user