Skip to content

Commit

Permalink
New field: file upload (fieldFile).
Browse files Browse the repository at this point in the history
  • Loading branch information
hansi90 committed Oct 11, 2017
1 parent 5099907 commit 5b74ead
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 29 deletions.
45 changes: 45 additions & 0 deletions src/fields/core/fieldFile.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<template lang="pug">
.wrapper
input.form-control(
id="ts01",
type="file",
:name="schema.inputName",
@change="schema.onChange || null",
:accept="schema.accept",
:multiple="schema.multiple",
:placeholder="schema.placeholder",
:readonly="schema.readonly",
:required="schema.required",
:disabled="disabled",)
</template>

<script>
import abstractField from "../abstractField";
import fecha from "fecha";
export default {
mixins: [abstractField]
};
</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>
57 changes: 28 additions & 29 deletions src/fields/core/fieldInput.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:type="schema.inputType",
:value="value",
@input="value = $event.target.value",
@change="onChange",
@change="schema.onChange || null",
:disabled="disabled",
:accept="schema.accept",
:alt="schema.alt",
Expand Down Expand Up @@ -37,22 +37,17 @@
</template>

<script>
import abstractField from "../abstractField";
import fecha from "fecha";
import abstractField from "../abstractField";
import fecha from "fecha";
export default {
mixins: [ abstractField ],
methods: {
onChange(event){
if (this.schema.inputType === "file") {
this.value = event.target.files;
}
},
formatValueToField(value) {
if (value != null) {
let dt;
switch(this.schema.inputType){
export default {
mixins: [abstractField],
methods: {
formatValueToField(value) {
if (value != null) {
let dt;
switch (this.schema.inputType) {
case "date":
dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value);
return fecha.format(dt, "YYYY-MM-DD");
Expand All @@ -62,16 +57,16 @@
case "datetime-local":
dt = this.schema.format ? fecha.parse(value, this.schema.format) : new Date(value);
return fecha.format(dt, "YYYY-MM-DDTHH:mm:ss");
}
}
return value;
},
}
formatValueToModel(value) {
if (value != null) {
let m;
switch (this.schema.inputType){
return value;
},
formatValueToModel(value) {
if (value != null) {
let m;
switch (this.schema.inputType) {
case "date":
m = fecha.parse(value, "YYYY-MM-DD");
if (m !== false) {
Expand Down Expand Up @@ -100,16 +95,20 @@
}
break;
case "number":
return Number(value);
return Number(value);
case "range":
return Number(value);
}
}
return value;
}
return value;
}
};
},
created () {
console.warn("The 'file' type in input field is deprecated. Use 'file' field instead.");
}
};
</script>

Expand Down

0 comments on commit 5b74ead

Please sign in to comment.