Skip to content

Commit

Permalink
feat(cfb-radio-input): add reset button
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabauke committed Dec 18, 2023
1 parent 2c1055b commit 3ba0248
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 52 deletions.
7 changes: 3 additions & 4 deletions packages/form/addon/components/cf-field/input/radio.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
>
<input
class="uk-radio uk-margin-small-right"
id={{option.slug}}
type="radio"
name={{@field.pk}}
value={{option.slug}}
checked={{eq option.slug @field.answer.value}}
disabled={{or option.disabled @disabled}}
{{on "change" this.updatSelection}}
{{on "change" (fn @onSave option.slug)}}
/>
{{#if (and option.disabled (not @disabled))}}
<del
Expand All @@ -24,9 +23,9 @@
{{/if}}
</label>
{{/each}}
{{#if (and (eq @field.question.raw.isRequired "false") this.checkedValue)}}
{{#if (and (eq @field.question.raw.isRequired "false") @field.answer.value)}}
<br />
<a href="#" {{on "click" this.resetSelected}}>{{t
<a data-test-radio-reset href="#" {{on "click" (fn @onSave null)}}>{{t
"caluma.form.power-select.reset"
}}</a>

Expand Down
26 changes: 0 additions & 26 deletions packages/form/addon/components/cf-field/input/radio.js

This file was deleted.

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,32 +86,32 @@ module("Integration | Component | cf-field/input/radio", function (hooks) {
});

test("it triggers save on click", async function (assert) {
assert.expect(1);
this.set("field", {
question: {
raw: {
isRequired: "false",
},
__typename: "ChoiceQuestion",
},
answer: {
value: "",
},
options: [
{
slug: "option-1",
label: "Option 1",
},
],
this.set("value", false);
this.set("raw", { isRequired: "false" });
this.set("onSave", (value) => {
this.set("value", value);
assert.step("save");
});
this.set("save", (value) => assert.strictEqual(value, "option-1"));

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

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

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

this.set("raw", { isRequired: "true" });
await click("label:nth-of-type(1) input");
assert.equal(true, true);

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

test("it renders disabled options", async function (assert) {
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 3ba0248

Please sign in to comment.