Fix completion of readonly-only forms

pull/718/head
tomek 3 weeks ago
parent 27a0d10525
commit 56a48ae0cd

@ -1114,7 +1114,8 @@ export default {
})
},
showCompleteButton () {
return this.completeButtonContainer && !this.isCompleted && !this.isInvite && this.isFormStarted &&
return this.completeButtonContainer && !this.isCompleted && !this.isInvite &&
(this.isFormStarted || this.stepFields.length === 0) &&
!this.stepFields.find((fields) => fields.some((f) => f.required && isEmpty(this.submittedValues[f.uuid])))
},
submitButtonText () {
@ -1667,7 +1668,7 @@ export default {
const submitStepIndex = this.currentStep
const stepPromise = ['signature', 'phone', 'initials', 'payment', 'verification', 'kba'].includes(this.currentField.type)
const stepPromise = ['signature', 'phone', 'initials', 'payment', 'verification', 'kba'].includes(this.currentField?.type)
? this.$refs.currentStep.submit
: () => Promise.resolve({})

@ -33,7 +33,9 @@
</button>
</modal-button>
<% end %>
<% unless @submitter.viewer? %>
<span id="complete_button_container" class="peer contents"></span>
<% end %>
<% if @form_configs[:with_delegate] && !@submitter.viewer? %>
<modal-button data-target="<%= delegate_modal_id = SecureRandom.uuid %>" class="hidden peer-empty:flex">
<button id="delegate_button" type="button" class="btn btn-sm !px-5"><%= t(:delegate) %></button>
@ -84,7 +86,9 @@
</button>
</modal-button>
<% end %>
<% unless @submitter.viewer? %>
<span id="complete_button_container_scroll" class="peer contents"></span>
<% end %>
<% if @form_configs[:with_delegate] && !@submitter.viewer? %>
<modal-button data-target="<%= delegate_modal_id %>" class="hidden peer-empty:flex">
<button id="delegate_button_mobile" type="button" class="btn btn-sm px-0" aria-label="<%= t(:delegate) %>">

@ -1317,6 +1317,29 @@ RSpec.describe 'Signing Form' do
expect(submitter.completed_at).to be_present
expect(field_value(submitter, 'First Name')).to eq 'John Doe'
end
it 'completes a form containing only readonly fields' do
template.fields.each do |field|
field['readonly'] = true
field['default_value'] = "Default #{field['name']}"
end
template.save!
submission.update!(template_fields: template.fields)
visit submit_form_path(slug: submitter.slug)
expect(page).to have_css('#complete_button_container button')
find('#complete_button_container button').click
expect(page).to have_content('Form has been completed!')
submitter.reload
expect(submitter.completed_at).to be_present
expect(field_value(submitter, 'First Name')).to eq 'Default First Name'
expect(field_value(submitter, 'Birthday')).to eq 'Default Birthday'
end
end
context 'when a view-only party opens the form' do
@ -1339,6 +1362,7 @@ RSpec.describe 'Signing Form' do
expect(page).to have_content(template.name)
expect(page).to have_no_css('#form_container')
expect(page).to have_no_css('#complete_button_container')
end
end
end

Loading…
Cancel
Save