From 7c03d20cc481965325f009536c3c74d99c3d4139 Mon Sep 17 00:00:00 2001 From: formsdev <136701234+formsdev@users.noreply.github.com> Date: Thu, 26 Oct 2023 18:28:35 +0530 Subject: [PATCH] Number input as Scale (#227) * Number input as Scale * scale input --------- Co-authored-by: Julien Nahum --- resources/js/components/forms/ScaleInput.vue | 102 ++++++++++++++++++ resources/js/components/forms/index.js | 4 +- .../components/open/forms/OpenFormField.vue | 7 ++ .../forms/fields/components/FieldOptions.vue | 46 +++++++- resources/js/config/form-themes.js | 18 ++++ 5 files changed, 173 insertions(+), 4 deletions(-) create mode 100644 resources/js/components/forms/ScaleInput.vue diff --git a/resources/js/components/forms/ScaleInput.vue b/resources/js/components/forms/ScaleInput.vue new file mode 100644 index 0000000..ea162cf --- /dev/null +++ b/resources/js/components/forms/ScaleInput.vue @@ -0,0 +1,102 @@ + + + diff --git a/resources/js/components/forms/index.js b/resources/js/components/forms/index.js index a81e16e..04e542d 100644 --- a/resources/js/components/forms/index.js +++ b/resources/js/components/forms/index.js @@ -15,6 +15,7 @@ import ImageInput from './ImageInput.vue' import RatingInput from './RatingInput.vue' import FlatSelectInput from './FlatSelectInput.vue' import ToggleSwitchInput from './ToggleSwitchInput.vue' +import ScaleInput from './ScaleInput.vue' // Components that are registered globaly. [ @@ -32,7 +33,8 @@ import ToggleSwitchInput from './ToggleSwitchInput.vue' ImageInput, RatingInput, FlatSelectInput, - ToggleSwitchInput + ToggleSwitchInput, + ScaleInput ].forEach(Component => { Vue.component(Component.name, Component) }) diff --git a/resources/js/components/open/forms/OpenFormField.vue b/resources/js/components/open/forms/OpenFormField.vue index eda7871..b96ae6d 100644 --- a/resources/js/components/open/forms/OpenFormField.vue +++ b/resources/js/components/open/forms/OpenFormField.vue @@ -150,6 +150,9 @@ export default { if (field.type === 'number' && field.is_rating && field.rating_max_value) { return 'RatingInput' } + if (field.type === 'number' && field.is_scale && field.scale_max_value) { + return 'ScaleInput' + } if (['select', 'multi_select'].includes(field.type) && field.without_dropdown) { return 'FlatSelectInput' } @@ -302,6 +305,10 @@ export default { inputProperties.accept = (this.form.is_pro && field.allowed_file_types) ? field.allowed_file_types : "" } else if (field.type === 'number' && field.is_rating) { inputProperties.numberOfStars = parseInt(field.rating_max_value) + } else if (field.type === 'number' && field.is_scale) { + inputProperties.minScale = parseInt(field.scale_min_value) ?? 1 + inputProperties.maxScale = parseInt(field.scale_max_value) ?? 5 + inputProperties.stepScale = parseInt(field.scale_step_value) ?? 1 } else if (field.type === 'number' || (field.type === 'phone_number' && field.use_simple_text_input)) { inputProperties.pattern = '/\d*' } else if (field.type === 'phone_number' && !field.use_simple_text_input) { diff --git a/resources/js/components/open/forms/fields/components/FieldOptions.vue b/resources/js/components/open/forms/fields/components/FieldOptions.vue index 1e208c6..a2eb163 100644 --- a/resources/js/components/open/forms/fields/components/FieldOptions.vue +++ b/resources/js/components/open/forms/fields/components/FieldOptions.vue @@ -73,13 +73,36 @@ Rating

- If enabled then this field will be star rating input. + Transform this field into a star rating input.

+ + + Scale + +

+ Transform this field into a scale/score input. +

+ @@ -510,8 +533,25 @@ export default { } }, initRating() { - if (this.field.is_rating && !this.field.rating_max_value) { - this.$set(this.field, 'rating_max_value', 5) + if (this.field.is_rating) { + this.$set(this.field, 'is_scale', false) + if (!this.field.rating_max_value) { + this.$set(this.field, 'rating_max_value', 5) + } + } + }, + initScale () { + if (this.field.is_scale) { + this.$set(this.field, 'is_rating', false) + if (!this.field.scale_min_value) { + this.$set(this.field, 'scale_min_value', 1) + } + if (!this.field.scale_max_value) { + this.$set(this.field, 'scale_max_value', 5) + } + if (!this.field.scale_step_value) { + this.$set(this.field, 'scale_step_value', 1) + } } }, onFieldOptionsChange(val) { diff --git a/resources/js/config/form-themes.js b/resources/js/config/form-themes.js index dab4996..1e4a15e 100644 --- a/resources/js/config/form-themes.js +++ b/resources/js/config/form-themes.js @@ -25,6 +25,12 @@ export const themes = { label: 'text-gray-700 dark:text-gray-300 font-semibold', input: 'relative w-full rounded-lg border-gray-300 flex-1 appearance-none border border-gray-300 dark:border-gray-600 w-full px-4 bg-white text-gray-700 placeholder-gray-400 dark:bg-notion-dark-light dark:text-gray-300 dark:placeholder-gray-600 shadow-sm text-base focus:outline-none focus:ring-2 focus:border-transparent', help: 'text-gray-400 dark:text-gray-500' + }, + ScaleInput: { + label: 'text-gray-700 dark:text-gray-300 font-semibold', + button: 'cursor-pointer text-gray-700 inline-block rounded-lg border-gray-300 px-4 py-2 flex-grow dark:bg-notion-dark-light dark:text-gray-300 text-center', + unselectedButton: 'bg-white hover:bg-gray-50 border', + help: 'text-gray-400 dark:text-gray-500' } }, simple: { @@ -50,6 +56,12 @@ export const themes = { label: 'text-gray-700 dark:text-gray-300 font-semibold', input: 'border-transparent flex-1 appearance-none border border-gray-300 dark:border-gray-600 w-full bg-white text-gray-700 dark:bg-notion-dark-light dark:text-gray-300 dark:placeholder-gray-500 placeholder-gray-400 text-base focus:outline-none focus:ring-1 focus:ring-opacity-100 focus:border-transparent focus:ring-2', help: 'text-gray-400 dark:text-gray-500' + }, + ScaleInput: { + label: 'text-gray-700 dark:text-gray-300 font-semibold', + button: 'flex-1 appearance-none border-gray-300 dark:border-gray-600 w-full py-2 px-2 bg-gray-50 text-gray-700 dark:bg-notion-dark-light dark:text-gray-300 text-center', + unselectedButton: 'bg-white hover:bg-gray-50 border -mx-4', + help: 'text-gray-400 dark:text-gray-500' } }, notion: { @@ -75,6 +87,12 @@ export const themes = { label: 'text-gray-900 dark:text-gray-100 mb-2 block mt-4', input: 'rounded border-transparent flex-1 appearance-none shadow-inner-notion border border-gray-300 dark:border-gray-600 w-full text-gray-900 bg-notion-input-background dark:bg-notion-dark-light shadow-inner dark:placeholder-gray-500 placeholder-gray-400 text-base focus:outline-none focus:ring-0 focus:ring-opacity-100 focus:border-transparent focus:ring-0 focus:shadow-focus-notion', help: 'text-notion-input-help dark:text-gray-500' + }, + ScaleInput: { + label: 'text-gray-900 dark:text-gray-100 mb-2 block mt-4', + button: 'rounded border-transparent flex-1 appearance-none shadow-inner-notion w-full py-2 px-2 bg-notion-input-background dark:bg-notion-dark-light text-gray-900 dark:text-gray-100 text-center', + unselectedButton: 'bg-notion-input-background dark:bg-notion-dark-light hover:bg-gray-50 border', + help: 'text-notion-input-help dark:text-gray-500' } }