2
0
mirror of https://github.com/frappe/books.git synced 2025-01-26 00:28:25 +00:00

- Base Input Sizing and Placeholder

- $formModal defaults
This commit is contained in:
thefalconx33 2019-08-14 13:18:04 +05:30
parent 22dcedda79
commit 4cbb99ed2d
9 changed files with 102 additions and 97 deletions

View File

@ -33,7 +33,7 @@
"file-saver": "^2.0.2", "file-saver": "^2.0.2",
"feather-icons": "^4.7.3", "feather-icons": "^4.7.3",
"file-loader": "^1.1.11", "file-loader": "^1.1.11",
"flatpickr": "^4.3.2", "flatpickr": "^4.6.2",
"frappe-datatable": "^1.13.5", "frappe-datatable": "^1.13.5",
"friendly-errors-webpack-plugin": "^1.7.0", "friendly-errors-webpack-plugin": "^1.7.0",
"html-webpack-plugin": "^3.2.0", "html-webpack-plugin": "^3.2.0",
@ -58,7 +58,7 @@
"socket.io": "^2.0.4", "socket.io": "^2.0.4",
"sqlite3": "^4.0.9", "sqlite3": "^4.0.9",
"vue": "^2.6.10", "vue": "^2.6.10",
"vue-flatpickr-component": "^7.0.4", "vue-flatpickr-component": "^8.1.2",
"vue-loader": "^15.2.6", "vue-loader": "^15.2.6",
"vue-router": "^3.0.7", "vue-router": "^3.0.7",
"vue-template-compiler": "^2.6.10", "vue-template-compiler": "^2.6.10",

View File

@ -1,25 +1,25 @@
<template> <template>
<div class="frappe-form"> <div class="frappe-form">
<form-actions <form-actions
class="p-3 border-bottom" class="p-3 border-bottom"
v-if="shouldRenderForm" v-if="shouldRenderForm"
:doc="doc" :doc="doc"
:links="links" :links="links"
@save="save" @save="save"
@submit="submit" @submit="submit"
@revert="revert" @revert="revert"
@print="print" @print="print"
/> />
<form-layout <form-layout
class="p-3" class="p-3"
v-if="shouldRenderForm" v-if="shouldRenderForm"
:doc="doc" :doc="doc"
:fields="meta.fields" :fields="meta.fields"
:layout="meta.layout" :layout="meta.layout"
:invalid="invalid" :invalid="invalid"
/> />
<not-found v-if="notFound" /> <not-found v-if="notFound" />
</div> </div>
</template> </template>
<script> <script>
import frappe from 'frappejs'; import frappe from 'frappejs';
@ -40,7 +40,8 @@ export default {
notFound: false, notFound: false,
invalid: false, invalid: false,
invalidFields: [], invalidFields: [],
links: [] links: [],
defaults: this.defaultValues
}; };
}, },
computed: { computed: {
@ -52,25 +53,36 @@ export default {
} }
}, },
async created() { async created() {
if (!this.defaults) {
this.defaults = {};
}
this.meta.fields.forEach(field => {
if (field.defaultValue)
this.defaults[field.fieldname] = field.defaultValue;
});
if (!this.name) return; if (!this.name) return;
try { try {
this.doc = await frappe.getDoc(this.doctype, this.name); this.doc = await frappe.getDoc(this.doctype, this.name);
if (this.doc.isNew() && this.meta.fields.map(df => df.fieldname).includes('name')) { if (
this.doc.isNew() &&
this.meta.fields.map(df => df.fieldname).includes('name')
) {
// For a user editable name field, // For a user editable name field,
// it should be unset since it is autogenerated // it should be unset since it is autogenerated
this.doc.set('name', ''); this.doc.set('name', '');
} }
if (this.defaultValues) { if (this.defaults) {
for (let fieldname in this.defaultValues) { for (let fieldname in this.defaults) {
const value = this.defaultValues[fieldname]; const value = this.defaults[fieldname];
this.doc.set(fieldname, value); await this.doc.set(fieldname, value);
} }
} }
this.docLoaded = true; this.docLoaded = true;
} catch (e) { } catch (e) {
console.error(e);
this.notFound = true; this.notFound = true;
} }
this.setLinks(); this.setLinks();
@ -89,7 +101,6 @@ export default {
} }
this.$emit('save', this.doc); this.$emit('save', this.doc);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
return; return;

View File

@ -90,14 +90,21 @@ export default {
getInputTag() { getInputTag() {
return 'input'; return 'input';
}, },
getFormControlSize() {
return this.docfield.size === 'small'
? 'form-control-sm'
: this.size === 'large'
? 'form-control-lg'
: '';
},
getInputClass() { getInputClass() {
return ['form-control', ...this.inputClass]; return ['form-control', this.getFormControlSize(), ...this.inputClass];
}, },
getInputAttrs() { getInputAttrs() {
return { return {
id: this.id, id: this.id,
type: 'text', type: 'text',
placeholder: '', placeholder: this.docfield.placeholder || '',
value: this.value, value: this.value,
required: this.docfield.required, required: this.docfield.required,
disabled: this.disabled disabled: this.disabled

View File

@ -1,7 +1,14 @@
<template> <template>
<div :class="{'form-group': !onlyInput}"> <div :class="{'form-group': !onlyInput}">
<label v-if="!onlyInput">{{ docfield.label }}</label> <label v-if="!onlyInput">{{ docfield.label }}</label>
<flat-pickr class="form-control" :value="value" :config="config" @on-change="emitChange"></flat-pickr> <flat-pickr
class="form-control"
:class="getFormControlSize()"
:placeholder="docfield.placeholder"
:value="value"
:config="config"
@on-change="emitChange"
></flat-pickr>
</div> </div>
</template> </template>
<script> <script>
@ -23,4 +30,7 @@ export default {
</script> </script>
<style lang="scss"> <style lang="scss">
@import '~flatpickr/dist/flatpickr.css'; @import '~flatpickr/dist/flatpickr.css';
.flat-pickr-input {
background-color: #fff;
}
</style> </style>

View File

@ -63,32 +63,6 @@ export default {
Time Time
}[this.docfield.fieldtype]; }[this.docfield.fieldtype];
}, },
dateConfig() {
if (this.docfield.fieldtype === 'Date') {
if (frappe.SystemSettings) {
let systemDateFormat = frappe.SystemSettings.dateFormat;
let divider = systemDateFormat.indexOf('/') != -1 ? '/' : '-';
let flatPickrFormat = '';
for (let char of systemDateFormat) {
if (
!flatPickrFormat.includes(char.toLowerCase()) &&
!flatPickrFormat.includes(char.toUpperCase())
) {
if (char.toLowerCase() !== 'y')
flatPickrFormat += char.toLowerCase() + divider;
else flatPickrFormat += char.toUpperCase() + divider;
}
}
return {
dateFormat: flatPickrFormat.slice(0, -1)
};
}
return {
dateFormat: 'Y/m/d'
};
}
},
isDisabled() { isDisabled() {
let disabled = this.docfield.disabled; let disabled = this.docfield.disabled;

View File

@ -1,31 +1,32 @@
<script> <script>
import Base from './Base'; import Base from './Base';
export default { export default {
extends: Base, extends: Base,
methods: { methods: {
getInputTag() { getInputTag() {
return 'select'; return 'select';
}, },
getInputAttrs() { getInputAttrs() {
return { return {
id: this.id, id: this.id,
required: this.docfield.required, required: this.docfield.required,
disabled: this.disabled disabled: this.disabled
}; };
}, },
getInputChildren(h) { getInputChildren(h) {
return this.docfield.options.map(option => return this.docfield.options.map(option =>
h('option', { h('option', {
attrs: { attrs: {
key: option, key: option,
selected: option === this.value selected: option === this.value,
}, value: option
domProps: { },
textContent: option domProps: {
} textContent: option
}) }
); })
} );
} }
} }
};
</script> </script>

View File

@ -217,7 +217,9 @@ export default {
}; };
}, },
activateFocus(i, fieldname) { activateFocus(i, fieldname) {
// FIX: enter pressing on a cell with a value throws error. if (this.isFocused(i, fieldname) && this.isEditing(i, fieldname)) {
return;
}
// this.deactivateEditing(); // this.deactivateEditing();
const docfield = this.columns.find(c => c.fieldname === fieldname); const docfield = this.columns.find(c => c.fieldname === fieldname);
this.currentlyFocused = { this.currentlyFocused = {
@ -238,14 +240,13 @@ export default {
this.currentlyFocused = {}; this.currentlyFocused = {};
} }
}, },
addRow() { async addRow() {
const rows = this.rows.slice(); const rows = this.rows.slice();
const newRow = { const newRow = { idx: rows.length };
idx: rows.length
};
for (let column of this.columns) { for (let column of this.columns) {
newRow[column.fieldname] = null; if (column.defaultValue) newRow[column.fieldname] = column.defaultValue;
else newRow[column.fieldname] = null;
} }
rows.push(newRow); rows.push(newRow);

View File

@ -1,12 +1,14 @@
<template> <template>
<div class="row pb-4"> <div class="d-flex px-1">
<div class="col-3" v-for="docfield in filterFields" :key="docfield.fieldname"> <div class="col-3" v-for="docfield in filterFields" :key="docfield.fieldname">
<frappe-control <frappe-control
v-if="shouldRenderField(docfield)" v-if="shouldRenderField(docfield)"
:docfield="docfield" :docfield="docfield"
:value="$data.filterValues[docfield.fieldname]" :value="$data.filterValues[docfield.fieldname]"
:onlyInput="true"
:doc="filterDoc" :doc="filterDoc"
@change="updateValue(docfield.fieldname, $event)" @change="updateValue(docfield.fieldname, $event)"
class="mb-4"
/> />
</div> </div>
</div> </div>
@ -46,10 +48,6 @@ export default {
return false; return false;
} }
if (field.fieldname === 'name' && !this.doc.isNew()) {
return false;
}
return true; return true;
}, },
updateValue(fieldname, value) { updateValue(fieldname, value) {

View File

@ -8,7 +8,6 @@ module.exports = {
if (typeof field === 'string') { if (typeof field === 'string') {
field = { fieldtype: field }; field = { fieldtype: field };
} }
if (field.fieldtype === 'Currency') { if (field.fieldtype === 'Currency') {
value = numberFormat.formatNumber(value); value = numberFormat.formatNumber(value);
} else if (field.fieldtype === 'Text') { } else if (field.fieldtype === 'Text') {
@ -25,6 +24,10 @@ module.exports = {
if (value === 'Invalid DateTime') { if (value === 'Invalid DateTime') {
value = ''; value = '';
} }
} else if (field.fieldtype === 'Check') {
typeof parseInt(value) === 'number'
? (value = parseInt(value))
: (value = Boolean(value));
} else { } else {
if (value === null || value === undefined) { if (value === null || value === undefined) {
value = ''; value = '';