Skip to content

Commit

Permalink
feat(form): add reset function for optional single choice questions
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Aboubacar <aboubacar.mchangama@adfinis.com>
Co-authored-by: Falk <falk.neumann@adfinis.com>
  • Loading branch information
3 people authored Dec 19, 2023
1 parent c321f08 commit f9c490f
Show file tree
Hide file tree
Showing 9 changed files with 46 additions and 6 deletions.
8 changes: 7 additions & 1 deletion packages/form/addon/components/cf-field/input/radio.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,10 @@
{{option.label}}
{{/if}}
</label>
{{/each}}
{{/each}}
{{#if (and @field.optional @field.answer.value)}}
<br />
<a href="" data-test-radio-reset {{on "click" this.reset}}>
{{t "caluma.form.power-select.reset"}}
</a>
{{/if}}
11 changes: 11 additions & 0 deletions packages/form/addon/components/cf-field/input/radio.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import { action } from "@ember/object";
import Component from "@glimmer/component";

export default class CfFieldInpuRadio extends Component {
@action
reset(event) {
event.preventDefault();

this.args.onSave(null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = {
{ name: "ember-flatpickr" },
{ name: "ember-in-viewport" },
{ name: "ember-math-helpers" },
{ name: "ember-truth-helpers" },
{ name: "ember-power-select" },
],
});
Expand Down
1 change: 1 addition & 0 deletions packages/form/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"ember-math-helpers": "^4.0.0",
"ember-power-select": "^7.2.0",
"ember-resources": "^6.4.2",
"ember-truth-helpers": "^4.0.3",
"ember-uikit": "^9.0.0",
"ember-validators": "^4.1.2",
"graphql": "^15.8.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,19 +86,33 @@ module("Integration | Component | cf-field/input/radio", function (hooks) {
});

test("it triggers save on click", async function (assert) {
assert.expect(1);

this.set("save", (value) => assert.strictEqual(value, "option-1"));
this.set("value", false);
this.set("optional", true);
this.set("onSave", (value) => {
this.set("value", value);
assert.step("save");
});

await render(hbs`<CfField::Input::Radio
@onSave={{this.save}}
@onSave={{this.onSave}}
@field={{hash
options=(array (hash slug="option-1" label="Option 1"))
question=(hash __typename="ChoiceQuestion")
answer=(hash value=this.value)
question=(hash __typename="ChoiceQuestion" slug="test")
optional=this.optional
}}
/>`);

await click("label:nth-of-type(1) input");
await click("[data-test-radio-reset]");

assert.verifySteps(["save", "save"]);

this.set("optional", false);
await click("label:nth-of-type(1) input");

assert.verifySteps(["save"]);
assert.dom("[data-test-radio-reset]").isNotVisible();
});

test("it renders disabled options", async function (assert) {
Expand Down
1 change: 1 addition & 0 deletions packages/form/translations/de.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ caluma:
options-empty: "Keine Optionen vorhanden"
search-placeholder: "Hier tippen um zu suchen"
search-empty: "Keine Optionen gefunden"
reset: "Zurücksetzen"

validation:
blank: "Dieses Feld darf nicht leer gelassen werden"
Expand Down
1 change: 1 addition & 0 deletions packages/form/translations/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ caluma:
options-empty: "No options available"
search-placeholder: "Type here to search options"
search-empty: "Search didn't match any options"
reset: "Reset"

validation:
blank: "This field can't be blank"
Expand Down
1 change: 1 addition & 0 deletions packages/form/translations/fr.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ caluma:
options-empty: "Pas d'options disponibles"
search-placeholder: "Tapez ici pour rechercher"
search-empty: "Pas d'options trouvées"
reset: "Réinitialiser"

validation:
blank: "Ce champ ne doit pas être laissé vide"
Expand Down
4 changes: 4 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit f9c490f

Please sign in to comment.