This repository has been archived by the owner on Feb 27, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #78 from anehx/question-required
Add toggle switch to set question required
- Loading branch information
Showing
13 changed files
with
141 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import RenderComponent from "ember-validated-form/components/validated-input/-themes/uikit/render"; | ||
import layout from "../templates/components/cfb-jexl-boolean-toggle-switch"; | ||
import jexl from "jexl"; | ||
import { reads } from "@ember/object/computed"; | ||
import { task } from "ember-concurrency"; | ||
|
||
export default RenderComponent.extend({ | ||
layout, | ||
|
||
didReceiveAttrs() { | ||
this._super(...arguments); | ||
|
||
this.get("_boolValue").perform(); | ||
}, | ||
|
||
boolValue: reads("_boolValue.lastSuccessful.value"), | ||
|
||
_boolValue: task(function*() { | ||
return yield jexl.eval(this.get("value")); | ||
}), | ||
|
||
actions: { | ||
toggle(boolValue) { | ||
this.get("update")(String(boolValue)); | ||
} | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,4 +3,6 @@ fragment QuestionInfo on Question { | |
slug | ||
label | ||
type | ||
isRequired | ||
isHidden | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
addon/templates/components/cfb-jexl-boolean-toggle-switch.hbs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{{component labelComponent}} | ||
|
||
<div class="uk-form-controls"> | ||
{{uk-toggle-switch | ||
value=boolValue | ||
size=size | ||
name=name | ||
on-toggle=(action 'toggle') | ||
}} | ||
</div> | ||
|
||
{{component hintComponent}} | ||
{{component errorComponent}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export { | ||
default | ||
} from "ember-caluma-form-builder/components/cfb-jexl-boolean-toggle-switch"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
60 changes: 60 additions & 0 deletions
60
tests/integration/components/cfb-jexl-boolean-toggle-switch-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { module, test } from "qunit"; | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import { render, click, settled } from "@ember/test-helpers"; | ||
import hbs from "htmlbars-inline-precompile"; | ||
|
||
module("Integration | Component | cfb-jexl-boolean-toggle-switch", function( | ||
hooks | ||
) { | ||
setupRenderingTest(hooks); | ||
|
||
test("it renders", async function(assert) { | ||
assert.expect(2); | ||
|
||
this.set("value", "false"); | ||
|
||
await render(hbs` | ||
{{cfb-jexl-boolean-toggle-switch | ||
name='test' | ||
value=value | ||
update=(action (mut value)) | ||
}} | ||
`); | ||
|
||
assert.dom("input[name=test]").isNotChecked(); | ||
|
||
this.set("value", "true"); | ||
|
||
await settled(); | ||
|
||
assert.dom("input[name=test]").isChecked(); | ||
}); | ||
|
||
test("it can toggle", async function(assert) { | ||
assert.expect(4); | ||
|
||
this.set("value", "false"); | ||
|
||
this.set("update", value => { | ||
assert.step("update"); | ||
|
||
this.set("value", value); | ||
}); | ||
|
||
await render(hbs` | ||
{{cfb-jexl-boolean-toggle-switch | ||
name='test' | ||
value=value | ||
update=(action update) | ||
}} | ||
`); | ||
|
||
assert.dom("input[name=test]").isNotChecked(); | ||
|
||
await click(".x-toggle"); | ||
|
||
assert.dom("input[name=test]").isChecked(); | ||
|
||
assert.verifySteps(["update"]); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7345,6 +7345,10 @@ jest-docblock@^21.0.0: | |
version "21.2.0" | ||
resolved "https://registry.yarnpkg.com/jest-docblock/-/jest-docblock-21.2.0.tgz#51529c3b30d5fd159da60c27ceedc195faf8d414" | ||
|
||
[email protected]: | ||
version "1.1.4" | ||
resolved "https://registry.yarnpkg.com/jexl/-/jexl-1.1.4.tgz#35cf86f881ea219d1e215c7a41e2e747ce6ee8a6" | ||
|
||
joi@^12.0.0: | ||
version "12.0.0" | ||
resolved "https://registry.yarnpkg.com/joi/-/joi-12.0.0.tgz#46f55e68f4d9628f01bbb695902c8b307ad8d33a" | ||
|