From faa50f6d5186bc341943ef84a22c42779c55f078 Mon Sep 17 00:00:00 2001 From: Jonas Cosandey Date: Mon, 20 Jan 2025 15:01:00 +0100 Subject: [PATCH] feat(float): add step configuration --- .../addon/components/cfb-form-editor/question.hbs | 8 ++++++++ .../addon/components/cfb-form-editor/question.js | 2 ++ .../addon/gql/mutations/save-float-question.graphql | 1 + .../addon/gql/queries/form-editor-question.graphql | 1 + packages/form-builder/addon/validations/question.js | 4 ++++ .../components/cfb-form-editor/question-test.js | 4 +++- packages/form-builder/translations/de.yaml | 1 + packages/form-builder/translations/en.yaml | 1 + packages/form-builder/translations/fr.yaml | 1 + packages/form-builder/translations/it.yaml | 1 + .../form/addon/components/cf-field/input/float.hbs | 2 +- .../form/addon/components/cf-field/input/float.js | 11 +++++++++++ packages/form/addon/gql/fragments/field.graphql | 1 + .../components/cf-field/input/float-test.js | 1 + packages/testing/addon/mirage-graphql/schema.graphql | 2 ++ 15 files changed, 39 insertions(+), 2 deletions(-) diff --git a/packages/form-builder/addon/components/cfb-form-editor/question.hbs b/packages/form-builder/addon/components/cfb-form-editor/question.hbs index 7f369c09d..00a83fe17 100644 --- a/packages/form-builder/addon/components/cfb-form-editor/question.hbs +++ b/packages/form-builder/addon/components/cfb-form-editor/question.hbs @@ -212,6 +212,14 @@ step="any" /> +
+ +
{{/if}} diff --git a/packages/form-builder/addon/components/cfb-form-editor/question.js b/packages/form-builder/addon/components/cfb-form-editor/question.js index 2c1d3f0d2..a72810a3f 100644 --- a/packages/form-builder/addon/components/cfb-form-editor/question.js +++ b/packages/form-builder/addon/components/cfb-form-editor/question.js @@ -97,6 +97,7 @@ export default class CfbFormEditorQuestion extends Component { integerMaxValue: null, floatMinValue: null, floatMaxValue: null, + floatStep: null, minLength: null, maxLength: null, defaultAnswer: null, @@ -253,6 +254,7 @@ export default class CfbFormEditorQuestion extends Component { return { minValue: parseFloat(changeset.get("floatMinValue")), maxValue: parseFloat(changeset.get("floatMaxValue")), + step: parseFloat(changeset.get("floatStep")), placeholder: changeset.get("placeholder"), hintText: changeset.get("hintText"), }; diff --git a/packages/form-builder/addon/gql/mutations/save-float-question.graphql b/packages/form-builder/addon/gql/mutations/save-float-question.graphql index be1eda61b..ed2de99cd 100644 --- a/packages/form-builder/addon/gql/mutations/save-float-question.graphql +++ b/packages/form-builder/addon/gql/mutations/save-float-question.graphql @@ -8,6 +8,7 @@ mutation SaveFloatQuestion($input: SaveFloatQuestionInput!) { ... on FloatQuestion { floatMinValue: minValue floatMaxValue: maxValue + floatStep: step hintText } } diff --git a/packages/form-builder/addon/gql/queries/form-editor-question.graphql b/packages/form-builder/addon/gql/queries/form-editor-question.graphql index 1c1ecaa93..14042d88e 100644 --- a/packages/form-builder/addon/gql/queries/form-editor-question.graphql +++ b/packages/form-builder/addon/gql/queries/form-editor-question.graphql @@ -20,6 +20,7 @@ query FormEditorQuestion($slug: String!) { ... on FloatQuestion { floatMaxValue: maxValue floatMinValue: minValue + floatStep: step placeholder hintText defaultAnswer { diff --git a/packages/form-builder/addon/validations/question.js b/packages/form-builder/addon/validations/question.js index 5d777764d..a26b5c4ea 100644 --- a/packages/form-builder/addon/validations/question.js +++ b/packages/form-builder/addon/validations/question.js @@ -53,6 +53,10 @@ export default { validateGtLt({ gt: "floatMinValue", allowNone: true }), ), ), + floatStep: or( + validateType("FloatQuestion", false), + validateNumber({ gt: 0, allowBlank: true }), + ), minLength: or( and( diff --git a/packages/form-builder/tests/integration/components/cfb-form-editor/question-test.js b/packages/form-builder/tests/integration/components/cfb-form-editor/question-test.js index 3a88c8ad1..1f5eca29c 100644 --- a/packages/form-builder/tests/integration/components/cfb-form-editor/question-test.js +++ b/packages/form-builder/tests/integration/components/cfb-form-editor/question-test.js @@ -303,7 +303,7 @@ module("Integration | Component | cfb-form-editor/question", function (hooks) { }); test("it can create a float question", async function (assert) { - assert.expect(7); + assert.expect(8); this.server.create("form", { slug: "test-form" }); @@ -313,6 +313,7 @@ module("Integration | Component | cfb-form-editor/question", function (hooks) { assert.strictEqual(question.slug, "slug"); assert.strictEqual(question.floatMinValue, -20); assert.strictEqual(question.floatMaxValue, 20); + assert.strictEqual(question.floatStep, 0.5); assert.step("after-submit"); }); @@ -330,6 +331,7 @@ module("Integration | Component | cfb-form-editor/question", function (hooks) { await fillIn("[name=slug]", "slug"); await fillIn("[name=floatMinValue]", -20); await fillIn("[name=floatMaxValue]", 20); + await fillIn("[name=floatStep]", 0.5); await click("button[type=submit]"); diff --git a/packages/form-builder/translations/de.yaml b/packages/form-builder/translations/de.yaml index 144b330b2..f145dadd1 100644 --- a/packages/form-builder/translations/de.yaml +++ b/packages/form-builder/translations/de.yaml @@ -72,6 +72,7 @@ caluma: max-value: "Maximaler Wert" min-length: "Minimale Länge" max-length: "Maximale Länge" + step: "Schritte" rowForm: "Formular für Tabelleneinträge" subForm: "Formular für Einträge" no-selection: "Keine Auswahl" diff --git a/packages/form-builder/translations/en.yaml b/packages/form-builder/translations/en.yaml index 9e97d7ad0..32a23c131 100644 --- a/packages/form-builder/translations/en.yaml +++ b/packages/form-builder/translations/en.yaml @@ -72,6 +72,7 @@ caluma: max-value: "Maximum value" min-length: "Minimum length" max-length: "Maximum length" + step: "Steps" rowForm: "Form to use for rows" subForm: "Form to use for entries" no-selection: "No selection" diff --git a/packages/form-builder/translations/fr.yaml b/packages/form-builder/translations/fr.yaml index e4bb1386b..8bd3e8d79 100644 --- a/packages/form-builder/translations/fr.yaml +++ b/packages/form-builder/translations/fr.yaml @@ -72,6 +72,7 @@ caluma: max-value: "Valeur maximale" min-length: "Longueur minimale" max-length: "Longueur maximale" + step: "Étapes" rowForm: "Formulaire pour les entrées de tableau" subForm: "Formulaire pour les entrées" no-selection: "Aucune sélection" diff --git a/packages/form-builder/translations/it.yaml b/packages/form-builder/translations/it.yaml index 7524aceed..af93a8e05 100644 --- a/packages/form-builder/translations/it.yaml +++ b/packages/form-builder/translations/it.yaml @@ -72,6 +72,7 @@ caluma: max-value: "Valore massimo" min-length: "Lunghezza minima" max-length: "Lunghezza massima" + step: "Passi" rowForm: "Modulo per righe delle tabelle" subForm: "Modulo per voci" no-selection: "Nessuna selezione" diff --git a/packages/form/addon/components/cf-field/input/float.hbs b/packages/form/addon/components/cf-field/input/float.hbs index 31f4627af..eaea45a68 100644 --- a/packages/form/addon/components/cf-field/input/float.hbs +++ b/packages/form/addon/components/cf-field/input/float.hbs @@ -1,6 +1,6 @@