-
Notifications
You must be signed in to change notification settings - Fork 533
new: new field 'input' #70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
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 hidden or 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,92 @@ | ||
<template lang="jade"> | ||
.wrapper | ||
input.form-control( | ||
:type="schema.inputType", | ||
v-model="value", | ||
:disabled="disabled", | ||
|
||
:accept="schema.accept", | ||
:alt="schema.alt", | ||
:autocomplete="schema.autocomplete", | ||
:checked="schema.checked", | ||
:dirname="schema.dirname", | ||
:formaction="schema.formaction", | ||
:formenctype="schema.formenctype", | ||
:formmethod="schema.formmethod", | ||
:formnovalidate="schema.formnovalidate", | ||
:formtarget="schema.formtarget", | ||
:height="schema.height", | ||
:list="schema.list", | ||
:max="schema.max", | ||
:maxlength="schema.maxlength", | ||
:min="schema.min", | ||
:multiple="schema.multiple", | ||
:pattern="schema.pattern", | ||
:placeholder="schema.placeholder", | ||
:readonly="schema.readonly", | ||
:required="schema.required", | ||
:size="schema.size", | ||
:src="schema.src", | ||
:step="schema.step", | ||
:width="schema.width", | ||
:files="schema.files") | ||
span.helper(v-if="schema.inputType === 'color' || schema.inputType === 'range'") {{ value }} | ||
</template> | ||
|
||
<script> | ||
import abstractField from "./abstractField"; | ||
|
||
export default { | ||
mixins: [ abstractField ], | ||
methods: { | ||
formatValueToField(value) { | ||
switch(this.schema.inputType){ | ||
case "date": | ||
return moment(value).format("YYYY-MM-DD"); | ||
case "datetime": | ||
return moment(value).format(); | ||
case "datetime-local": | ||
return moment(value).format("YYYY-MM-DDTHH:mm:ss"); | ||
default: | ||
return value; | ||
} | ||
}, | ||
formatValueToModel(value) { | ||
console.log(this.schema.inputType, typeof value); | ||
if (value != null) { | ||
if (this.schema.inputType === "date" || | ||
this.schema.inputType === "datetime" || | ||
this.schema.inputType === "datetimelocal") { | ||
return new Date(value).getTime(); | ||
}else{ | ||
return value; | ||
} | ||
} else { | ||
return value; | ||
} | ||
} | ||
} | ||
}; | ||
|
||
</script> | ||
|
||
<style lang="sass"> | ||
.vue-form-generator .field-input { | ||
.wrapper { | ||
width: 100%; | ||
} | ||
input[type="radio"] { | ||
width: 100%; | ||
} | ||
input[type="color"] { | ||
width: 60px; | ||
} | ||
input[type="range"] { | ||
padding: 0; | ||
} | ||
|
||
.helper { | ||
margin: auto 0.5em; | ||
} | ||
} | ||
</style> |
This file contains hidden or 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,125 @@ | ||
import { expect } from "chai"; | ||
import { createVueField, trigger, checkAttribute } from "../util"; | ||
|
||
import Vue from "vue"; | ||
import fieldInput from "src/fields/fieldInput.vue"; | ||
|
||
Vue.component("fieldInput", fieldInput); | ||
|
||
let el, vm, field; | ||
|
||
function createField(test, schema = {}, model = null, disabled = false, options) { | ||
[el, vm, field] = createVueField(test, "fieldInput", schema, model, disabled, options); | ||
} | ||
|
||
describe("fieldInput.vue", function() { | ||
|
||
describe("check template", () => { | ||
let schema = { | ||
type: "input", | ||
inputType: "text", | ||
label: "Name", | ||
model: "name", | ||
autocomplete: "off", | ||
placeholder: "Field placeholder", | ||
readonly: false | ||
}; | ||
let model = { name: "John Doe" }; | ||
let input; | ||
|
||
before(() => { | ||
createField(this, schema, model, false); | ||
input = el.getElementsByTagName("input")[0]; | ||
}); | ||
|
||
it("should contain an input text element", () => { | ||
expect(field).to.be.exist; | ||
expect(field.$el).to.be.exist; | ||
|
||
expect(input).to.be.defined; | ||
expect(input.type).to.be.equal("text"); | ||
expect(input.classList.contains("form-control")).to.be.true; | ||
}); | ||
|
||
it("should contain the value", (done) => { | ||
vm.$nextTick(() => { | ||
expect(input.value).to.be.equal("John Doe"); | ||
done(); | ||
}); | ||
}); | ||
|
||
let inputTypes = new Map([ | ||
["text", ["autocomplete", "disabled", "placeholder", "readonly"]], | ||
["password", ["autocomplete", "disabled", "placeholder", "readonly"]], | ||
["checkbox", ["autocomplete", "disabled"]], | ||
// ["radio", [] ], | ||
// ["button", [] ], | ||
// ["submit", [] ], | ||
// ["reset", [] ], | ||
// ["file", [] ], | ||
// ["hidden", [] ], | ||
// ["image", [] ], | ||
// ["datetime", ], | ||
// ["datetime", ], | ||
// ["date", ], | ||
// ["month", ], | ||
// ["time", ], | ||
// ["week", ], | ||
["number", ["autocomplete", "disabled", "placeholder", "readonly"]], | ||
// ["range", ["autocomplete"]], | ||
["email", ["autocomplete", "disabled", "placeholder", "readonly"]], | ||
["url", ["autocomplete", "disabled", "placeholder", "readonly"]], | ||
// ["search", ], | ||
["tel", ["autocomplete", "disabled", "placeholder", "readonly"]], | ||
["color", ["autocomplete"]] | ||
]); | ||
for (let [inputType, attributes] of inputTypes) { | ||
|
||
describe("change type of input", () => { | ||
|
||
it("should become a " + inputType, function(done) { | ||
field.schema.inputType = inputType; | ||
vm.$nextTick(() => { | ||
expect(input.type).to.be.equal(inputType); | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
describe("check optional attribute", () => { | ||
|
||
attributes.forEach(function(name) { | ||
it("should set " + name, function(done) { | ||
checkAttribute(name, vm, input, field, schema, done); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); | ||
} | ||
|
||
it("input value should be the model value after changed", (done) => { | ||
model.name = "Jane Doe"; | ||
vm.$nextTick(() => { | ||
expect(input.value).to.be.equal("Jane Doe"); | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
it("model value should be the input value if changed", (done) => { | ||
input.value = "John Smith"; | ||
trigger(input, "input"); | ||
|
||
vm.$nextTick(() => { | ||
expect(model.name).to.be.equal("John Smith"); | ||
done(); | ||
}); | ||
|
||
}); | ||
|
||
}); | ||
|
||
}); |
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.
Please remove this log message and after it I will merge.
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.
done
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.
Thanks
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.
You still need to merge, no ? I think you just approved the changes
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.
Just waited the green lights :)
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.
sorry I did not get it 👍