Skip to content

Commit

Permalink
fix(form): fix resetting of values on slow input
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonas Metzener authored and czosel committed Jul 1, 2019
1 parent cfc9e85 commit e07388a
Show file tree
Hide file tree
Showing 15 changed files with 41 additions and 41 deletions.
10 changes: 5 additions & 5 deletions addon/components/cf-field/input/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ export default Component.extend({
intl: service(),
apollo: service(),

downloadUrl: reads("field.answer.fileValue.downloadUrl"),
downloadName: reads("field.answer.fileValue.name"),
downloadUrl: reads("field.answer.value.downloadUrl"),
downloadName: reads("field.answer.value.name"),

placeholder: computed("field.answer.fileValue", function() {
return this.get("field.answer.fileValue")
placeholder: computed("field.answer.value", function() {
return this.get("field.answer.value")
? this.intl.t("caluma.form.changeFile")
: this.intl.t("caluma.form.selectFile");
}),
Expand Down Expand Up @@ -81,7 +81,7 @@ export default Component.extend({
try {
await this._uploadFile(file, fileValue.uploadUrl);

this.set("field.answer.fileValue", {
this.set("field.answer.value", {
name: file.name,
downloadUrl: fileValue.downloadUrl
});
Expand Down
2 changes: 1 addition & 1 deletion addon/components/cf-field/input/float.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default Component.extend({
"step",
"disabled",
"field.id:name",
"field.answer.floatValue:value",
"field.answer.value:value",
"field.question.floatMinValue:min",
"field.question.floatMaxValue:max"
],
Expand Down
2 changes: 1 addition & 1 deletion addon/components/cf-field/input/integer.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default Component.extend({
"step",
"disabled",
"field.id:name",
"field.answer.integerValue:value",
"field.answer.value:value",
"field.question.integerMinValue:min",
"field.question.integerMaxValue:max"
],
Expand Down
2 changes: 1 addition & 1 deletion addon/components/cf-field/input/text.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default Component.extend({
"type",
"disabled",
"field.id:name",
"field.answer.stringValue:value",
"field.answer.value:value",
"field.question.placeholder:placeholder"
],
type: "text",
Expand Down
2 changes: 1 addition & 1 deletion addon/components/cf-field/input/textarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export default Component.extend({
attributeBindings: [
"disabled",
"field.id:name",
"field.answer.stringValue:value",
"field.answer.value:value",
"field.question.textareaMaxLength:maxlength"
],

Expand Down
2 changes: 1 addition & 1 deletion addon/templates/components/cf-field/input/radio.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
type="radio"
name={{field.id}}
value={{option.slug}}
checked={{eq option.slug field.answer.stringValue}}
checked={{eq option.slug field.answer.value}}
disabled={{disabled}}
onchange={{action onSave option.slug}}
>
Expand Down
10 changes: 5 additions & 5 deletions tests/integration/components/cf-field/input-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module("Integration | Component | cf-field/input", function(hooks) {
__typename="TextQuestion"
)
answer=(hash
stringValue="Test"
value="Test"
)
)
}}
Expand All @@ -36,7 +36,7 @@ module("Integration | Component | cf-field/input", function(hooks) {
__typename="TextareaQuestion"
)
answer=(hash
stringValue="Test"
value="Test"
)
)
}}
Expand All @@ -56,7 +56,7 @@ module("Integration | Component | cf-field/input", function(hooks) {
__typename="IntegerQuestion"
)
answer=(hash
integerValue=5
value=5
)
)
}}
Expand All @@ -76,7 +76,7 @@ module("Integration | Component | cf-field/input", function(hooks) {
__typename="FloatQuestion"
)
answer=(hash
floatValue=0.55
value=0.55
)
)
}}
Expand Down Expand Up @@ -104,7 +104,7 @@ module("Integration | Component | cf-field/input", function(hooks) {
__typename="RadioQuestion"
)
answer=(hash
stringValue="option-1"
value="option-1"
)
)
}}
Expand Down
8 changes: 4 additions & 4 deletions tests/integration/components/cf-field/input/file-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ module("Integration | Component | cf-field/input/file", function(hooks) {
this.set("field", {
answer: {
id: btoa("FileAnswer:1"),
fileValue: {}
value: {}
}
});

this.set("onSave", name => ({
fileValue: { uploadUrl: `/minio/upload/${name}` }
value: { uploadUrl: `/minio/upload/${name}` }
}));

let payload_good = new File(["test"], "good.txt", { type: "text/plain" });
Expand All @@ -41,7 +41,7 @@ module("Integration | Component | cf-field/input/file", function(hooks) {
this.set("field", {
answer: {
id: btoa("FileAnswer:1"),
fileValue: {
value: {
downloadUrl: "/minio/download/good.txt",
name: "good.txt"
}
Expand All @@ -58,7 +58,7 @@ module("Integration | Component | cf-field/input/file", function(hooks) {
await render(hbs`{{cf-field/input/file field=field}}`);

assert.dom(".uk-button").exists();
assert.dom(".uk-button").hasText(this.field.answer.fileValue.name);
assert.dom(".uk-button").hasText(this.field.answer.value.name);

// Skip this part until the Mirage/GraphQL stuff is sorted out.
//await click(".uk-button");
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/cf-field/input/float-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module("Integration | Component | cf-field/input/float", function(hooks) {
field=(hash
id="test"
answer=(hash
floatValue=1.045
value=1.045
)
question=(hash
floatMinValue=0.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module("Integration | Component | cf-field/input/integer", function(hooks) {
field=(hash
id="test"
answer=(hash
integerValue=3
value=3
)
question=(hash
integerMinValue=1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ module("Integration | Component | cf-field/input/powerselect", function(hooks) {
this.set("singleChoiceField", {
id: "test-single",
answer: {
stringValue: null,
value: null,
__typename: "StringAnswer"
},
question: {
Expand All @@ -28,7 +28,7 @@ module("Integration | Component | cf-field/input/powerselect", function(hooks) {
this.set("multipleChoiceField", {
id: "test-multiple",
answer: {
listValue: null,
value: null,
__typename: "ListAnswer"
},
question: {
Expand Down Expand Up @@ -60,7 +60,7 @@ module("Integration | Component | cf-field/input/powerselect", function(hooks) {
assert.expect(3);

this.set("onSave", choice => {
this.set("singleChoiceField.answer.stringValue", choice);
this.set("singleChoiceField.answer.value", choice);
});

await render(
Expand All @@ -76,7 +76,7 @@ module("Integration | Component | cf-field/input/powerselect", function(hooks) {
assert.dom(".ember-power-select-option").exists({ count: 3 });
await click(".ember-power-select-option:first-child");

assert.equal(this.singleChoiceField.answer.stringValue, "option-1");
assert.equal(this.singleChoiceField.answer.value, "option-1");
});

test("it renders (multiple)", async function(assert) {
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/cf-field/input/radio-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module("Integration | Component | cf-field/input/radio", function(hooks) {
field=(hash
id="test"
answer=(hash
stringValue="option-1"
value="option-1"
)
question=(hash
choiceOptions=(hash
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/components/cf-field/input/text-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module("Integration | Component | cf-field/input/text", function(hooks) {
field=(hash
id="test"
answer=(hash
stringValue="Test"
value="Test"
)
question=(hash
textMaxLength=5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ module("Integration | Component | cf-field/input/textarea", function(hooks) {
field=(hash
id="test"
answer=(hash
stringValue="Test Test Test"
value="Test Test Test"
)
question=(hash
textareaMaxLength=200
Expand Down
26 changes: 13 additions & 13 deletions tests/unit/lib/field-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ module("Unit | Library | field", function(hooks) {
_answer: this.answer
});

assert.equal(field.answer.stringValue, "Test");
assert.equal(field.answer.value, "Test");

const fieldWithoutAnswer = Field.create(this.owner.ownerInjection(), {
_question: this.question,
_document: this.document,
_answer: null
});

assert.equal(fieldWithoutAnswer.answer.stringValue, null);
assert.equal(fieldWithoutAnswer.answer.value, null);
assert.equal(fieldWithoutAnswer.answer.__typename, "StringAnswer");
});

Expand Down Expand Up @@ -95,7 +95,7 @@ module("Unit | Library | field", function(hooks) {
await field.validate.perform();
assert.deepEqual(field.errors, []);

field.set("answer.stringValue", "");
field.set("answer.value", "");

await field.validate.perform();
assert.deepEqual(field.errors, ["This field can't be blank"]);
Expand Down Expand Up @@ -136,7 +136,7 @@ module("Unit | Library | field", function(hooks) {
await field.validate.perform();
assert.deepEqual(field.errors, []);

field.set("answer.stringValue", "Testx");
field.set("answer.value", "Testx");

await field.validate.perform();
assert.deepEqual(field.errors, [
Expand All @@ -163,7 +163,7 @@ module("Unit | Library | field", function(hooks) {
await field.validate.perform();
assert.deepEqual(field.errors, []);

field.set("answer.stringValue", "Testx");
field.set("answer.value", "Testx");

await field.validate.perform();
assert.deepEqual(field.errors, [
Expand All @@ -190,21 +190,21 @@ module("Unit | Library | field", function(hooks) {

assert.equal(field._validateIntegerQuestion(), true);

field.set("answer.integerValue", 1);
field.set("answer.value", 1);

await field.validate.perform();
assert.deepEqual(field.errors, [
"The value of this field must be greater than or equal to 2"
]);

field.set("answer.integerValue", 3);
field.set("answer.value", 3);

await field.validate.perform();
assert.deepEqual(field.errors, [
"The value of this field must be less than or equal to 2"
]);

field.set("answer.integerValue", 1.5);
field.set("answer.value", 1.5);

await field.validate.perform();
assert.deepEqual(field.errors, [
Expand Down Expand Up @@ -232,14 +232,14 @@ module("Unit | Library | field", function(hooks) {
await field.validate.perform();
assert.deepEqual(field.errors, []);

field.set("answer.floatValue", 1.4);
field.set("answer.value", 1.4);

await field.validate.perform();
assert.deepEqual(field.errors, [
"The value of this field must be greater than or equal to 1.5"
]);

field.set("answer.floatValue", 2.6);
field.set("answer.value", 2.6);

await field.validate.perform();
assert.deepEqual(field.errors, [
Expand Down Expand Up @@ -274,7 +274,7 @@ module("Unit | Library | field", function(hooks) {
await field.validate.perform();
assert.deepEqual(field.errors, []);

field.set("answer.stringValue", "invalid-option");
field.set("answer.value", "invalid-option");

await field.validate.perform();
assert.deepEqual(field.errors, [
Expand Down Expand Up @@ -309,14 +309,14 @@ module("Unit | Library | field", function(hooks) {
await field.validate.perform();
assert.deepEqual(field.errors, []);

field.set("answer.listValue", ["option-1", "invalid-option"]);
field.set("answer.value", ["option-1", "invalid-option"]);

await field.validate.perform();
assert.deepEqual(field.errors, [
"'invalid-option' is not a valid value for this field"
]);

field.set("answer.listValue", ["invalid-option", "other-invalid-option"]);
field.set("answer.value", ["invalid-option", "other-invalid-option"]);

await field.validate.perform();
assert.deepEqual(field.errors, [
Expand Down

0 comments on commit e07388a

Please sign in to comment.