Skip to content
Permalink
Browse files

fix(form): fix resetting of values on slow input

  • Loading branch information...
anehx authored and czosel committed Jul 1, 2019
1 parent cfc9e85 commit e07388a93bc7ba409766581a92e10e6bb1dbe77f
@@ -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");
}),
@@ -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
});
@@ -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"
],
@@ -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"
],
@@ -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",
@@ -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"
],

@@ -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}}
>
@@ -16,7 +16,7 @@ module("Integration | Component | cf-field/input", function(hooks) {
__typename="TextQuestion"
)
answer=(hash
stringValue="Test"
value="Test"
)
)
}}
@@ -36,7 +36,7 @@ module("Integration | Component | cf-field/input", function(hooks) {
__typename="TextareaQuestion"
)
answer=(hash
stringValue="Test"
value="Test"
)
)
}}
@@ -56,7 +56,7 @@ module("Integration | Component | cf-field/input", function(hooks) {
__typename="IntegerQuestion"
)
answer=(hash
integerValue=5
value=5
)
)
}}
@@ -76,7 +76,7 @@ module("Integration | Component | cf-field/input", function(hooks) {
__typename="FloatQuestion"
)
answer=(hash
floatValue=0.55
value=0.55
)
)
}}
@@ -104,7 +104,7 @@ module("Integration | Component | cf-field/input", function(hooks) {
__typename="RadioQuestion"
)
answer=(hash
stringValue="option-1"
value="option-1"
)
)
}}
@@ -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" });
@@ -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"
}
@@ -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");
@@ -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
@@ -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
@@ -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: {
@@ -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: {
@@ -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(
@@ -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) {
@@ -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
@@ -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
@@ -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
@@ -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");
});

@@ -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"]);
@@ -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, [
@@ -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, [
@@ -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, [
@@ -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, [
@@ -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, [
@@ -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, [

0 comments on commit e07388a

Please sign in to comment.
You can’t perform that action at this time.