diff --git a/app/javascript/components/field.vue b/app/javascript/components/field.vue index 4f58e235..1f297bd0 100644 --- a/app/javascript/components/field.vue +++ b/app/javascript/components/field.vue @@ -41,7 +41,7 @@ v-for="(area, index) in areas" :key="index" > - {{ area }} + Area {{ index + 1 }} diff --git a/app/javascript/elements/flow_view.js b/app/javascript/elements/flow_view.js index 9f47fe65..1a440d88 100644 --- a/app/javascript/elements/flow_view.js +++ b/app/javascript/elements/flow_view.js @@ -4,8 +4,7 @@ import { actionable } from '@github/catalyst/lib/actionable' export default actionable(targetable(class extends HTMLElement { static [target.static] = [ 'form', - 'completed', - 'submitButton' + 'completed' ] static [targets.static] = [ @@ -22,16 +21,28 @@ export default actionable(targetable(class extends HTMLElement { }) } - submitSignature () { - this.submitButton.click() - } - setVisibleStep (uuid) { this.steps.forEach((step) => { 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) { diff --git a/app/javascript/elements/signature_pad.js b/app/javascript/elements/signature_pad.js index 4f1f9b08..0c1b207b 100644 --- a/app/javascript/elements/signature_pad.js +++ b/app/javascript/elements/signature_pad.js @@ -7,7 +7,9 @@ import { DirectUpload } from '@rails/activestorage' export default actionable(targetable(class extends HTMLElement { static [target.static] = [ 'canvas', - 'input' + 'input', + 'okButton', + 'clearButton' ] connectedCallback () { @@ -17,6 +19,8 @@ export default actionable(targetable(class extends HTMLElement { submit (e) { e?.preventDefault() + this.okButton.disabled = true + this.canvas.toBlob((blob) => { const file = new File([blob], 'signature.jpg', { type: 'image/jpg' }) diff --git a/app/views/submit_flow/show.html.erb b/app/views/submit_flow/show.html.erb index e30b2786..e3882175 100644 --- a/app/views/submit_flow/show.html.erb +++ b/app/views/submit_flow/show.html.erb @@ -21,18 +21,25 @@ <% visible_step_index = nil %> <% @submission.flow.fields.each_with_index do |field, index| %> <% visible_step_index ||= index if @submission.values[field['uuid']].blank? %> - + <% if index != 0 %> <% end %> +
<% if index == @submission.flow.fields.size - 1 %> +
+ +
<% end %> <% if field['type'].in?(['text', 'date']) %> - 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'] %>]"> + 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'] %>]"> +
+ +
<% elsif field['type'] == 'select' %> +
+ +
<% elsif field['type'] == 'image' || field['type'] == 'attachment' %>
@@ -52,24 +62,48 @@ +
+ +
<% elsif field['type'] == 'signature' %> - - - - +
+
<% elsif field['type'] == 'radio' %> + <% field['options'].each do |option| %> +
+ id="<%= field['uuid'] + option %>" type="radio" name="values[<%= field['uuid'] %>]" value="<%= option %>"> + +
+ <% end %> +
+ +
<% elsif field['type'] == 'checkbox' %> + <% field['options'].each do |option| %> +
+ id="<%= field['uuid'] + option %>" type="checkbox" name="values[<%= field['uuid'] %>]" value="<%= option %>"> + +
+ <% end %> +
+ +
<% end %>
<% end %> -