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 4
Add checkbox field type #19
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import Component from "@ember/component"; | ||
import layout from "../../../templates/components/cf-field/input/checkbox"; | ||
|
||
/** | ||
* Input component for the checkbox question type | ||
* | ||
* @class CfFieldInputCheckboxComponent | ||
*/ | ||
export default Component.extend({ | ||
layout, | ||
tagName: "" | ||
}); |
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,16 @@ | ||
{{#each field.question.checkboxOptions.edges as |optionEdge i|}} | ||
{{#let optionEdge.node as |option|}} | ||
{{#if (gt i 0)}}<br>{{/if}} | ||
<label> | ||
<input | ||
class="uk-checkbox uk-margin-small-right" | ||
type="checkbox" | ||
name={{field.id}} | ||
value={{option.slug}} | ||
checked={{contains option.slug field.answer.listValue}} | ||
> | ||
{{option.label}} | ||
</label> | ||
{{/let}} | ||
{{/each}} | ||
|
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 @@ | ||
export { default } from "ember-caluma-form/components/cf-field/input/checkbox"; |
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
54 changes: 54 additions & 0 deletions
54
tests/integration/components/cf-field/input/checkbox-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,54 @@ | ||
import { module, test } from "qunit"; | ||
import { setupRenderingTest } from "ember-qunit"; | ||
import { render } from "@ember/test-helpers"; | ||
import hbs from "htmlbars-inline-precompile"; | ||
|
||
module("Integration | Component | cf-field/input/checkbox", function(hooks) { | ||
setupRenderingTest(hooks); | ||
|
||
test("it renders", async function(assert) { | ||
assert.expect(12); | ||
|
||
await render(hbs` | ||
{{cf-field/input/checkbox | ||
field=(hash | ||
id="test" | ||
answer=(hash | ||
listValue=(array "option-1" "option-2") | ||
) | ||
question=(hash | ||
checkboxOptions=(hash | ||
edges=(array | ||
(hash node=(hash slug="option-1" label="Option 1")) | ||
(hash node=(hash slug="option-2" label="Option 2")) | ||
(hash node=(hash slug="option-3" label="Option 3")) | ||
) | ||
) | ||
) | ||
) | ||
}} | ||
`); | ||
|
||
assert.dom("input[type=checkbox]").exists({ count: 3 }); | ||
assert.dom("label").exists({ count: 3 }); | ||
assert.dom("br").exists({ count: 2 }); | ||
assert.dom("label:nth-of-type(3) + br").doesNotExist(); | ||
|
||
assert.dom("label:nth-of-type(1)").hasText("Option 1"); | ||
assert.dom("label:nth-of-type(2)").hasText("Option 2"); | ||
assert.dom("label:nth-of-type(3)").hasText("Option 3"); | ||
|
||
assert | ||
.dom("label:nth-of-type(1) input[type=checkbox]") | ||
.hasValue("option-1"); | ||
assert | ||
.dom("label:nth-of-type(2) input[type=checkbox]") | ||
.hasValue("option-2"); | ||
assert | ||
.dom("label:nth-of-type(3) input[type=checkbox]") | ||
.hasValue("option-3"); | ||
|
||
assert.dom("label:nth-of-type(1) input[type=checkbox]").isChecked(); | ||
assert.dom("label:nth-of-type(2) input[type=checkbox]").isChecked(); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be more readable to specify those nested objects in JS and pass them in as
field=field
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a matter of taste I think. In this case it would maybe make sense, but I'd prefer to do it everywhere or nowhere in those tests. I think the best way would be to do it everywhere but in a seperate PR. Agree?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created an issue: #38