From 4094bb03b7386f4d65f84e294060664ee3bcb0f0 Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Tue, 20 Jun 2023 00:24:39 +0300 Subject: [PATCH] allow to make form field optional --- app/javascript/submission_form/area.vue | 3 + app/javascript/submission_form/form.vue | 55 ++++++++++++++----- app/javascript/template_builder/area.vue | 20 +++++++ app/javascript/template_builder/builder.vue | 5 ++ .../template_builder/contenteditable.vue | 26 ++++++--- app/javascript/template_builder/field.vue | 32 ++++++++++- .../template_builder/field_type.vue | 2 +- app/views/layouts/application.html.erb | 4 +- app/views/layouts/form.html.erb | 4 +- app/views/submit_form/completed.html.erb | 4 +- app/views/submit_form/show.html.erb | 2 +- config/routes.rb | 2 +- 12 files changed, 127 insertions(+), 32 deletions(-) diff --git a/app/javascript/submission_form/area.vue b/app/javascript/submission_form/area.vue index dc209e53..26925044 100644 --- a/app/javascript/submission_form/area.vue +++ b/app/javascript/submission_form/area.vue @@ -28,6 +28,9 @@ +
{{ currentField.name }} + >{{ currentField.name }} + +
{{ currentField.name }} + >{{ currentField.name }} + +
{{ currentField.name }} + >{{ currentField.name }} + + + +
@@ -52,6 +59,11 @@ export default { required: false, default: 30 }, + withRequired: { + type: Boolean, + required: false, + default: false + }, iconStrokeWidth: { type: Number, required: false, @@ -79,10 +91,10 @@ export default { this.$emit('update:model-value', this.value) this.$emit('blur', e) }, - onPencilClick () { + focusContenteditable () { this.$refs.contenteditable.focus() }, - onEnter () { + blurContenteditable () { this.$refs.contenteditable.blur() } } diff --git a/app/javascript/template_builder/field.vue b/app/javascript/template_builder/field.vue index 6cfc7a40..84bfbb8c 100644 --- a/app/javascript/template_builder/field.vue +++ b/app/javascript/template_builder/field.vue @@ -27,7 +27,28 @@ @blur="onNameBlur" />
-
+
+ + +
+
f.type === this.field.type).indexOf(this.field) @@ -192,6 +218,8 @@ export default { }, methods: { onNameFocus (e) { + this.isNameFocus = true + if (!this.field.name) { setTimeout(() => { this.$refs.name.$refs.contenteditable.innerText = ' ' @@ -220,6 +248,8 @@ export default { this.field.name = '' this.$refs.name.$refs.contenteditable.innerText = this.defaultName } + + this.isNameFocus = false }, removeArea (area) { this.field.areas.splice(this.field.areas.indexOf(area), 1) diff --git a/app/javascript/template_builder/field_type.vue b/app/javascript/template_builder/field_type.vue index bfdf2859..cf3766f7 100644 --- a/app/javascript/template_builder/field_type.vue +++ b/app/javascript/template_builder/field_type.vue @@ -2,7 +2,7 @@