2
0
mirror of https://github.com/frappe/books.git synced 2024-09-20 11:29:00 +00:00

Focus on form section's first input

This commit is contained in:
thefalconx33 2019-08-05 17:16:35 +05:30
parent d9b5e56072
commit 22dcedda79
3 changed files with 38 additions and 33 deletions

View File

@ -2,7 +2,12 @@
<div class="frappe-form-actions d-flex justify-content-between align-items-center"> <div class="frappe-form-actions d-flex justify-content-between align-items-center">
<h5 class="m-0">{{ title }}</h5> <h5 class="m-0">{{ title }}</h5>
<div class="d-flex"> <div class="d-flex">
<f-button primary v-if="showSave" :disabled="disableSave" @click="$emit('save')">{{ _('Save') }}</f-button> <f-button
primary
v-if="showSave"
:disabled="disableSave"
@click="$emit('save')"
>{{ _('Save') }}</f-button>
<f-button primary v-if="showSubmit" @click="$emit('submit')">{{ _('Submit') }}</f-button> <f-button primary v-if="showSubmit" @click="$emit('submit')">{{ _('Submit') }}</f-button>
<f-button secondary v-if="showRevert" @click="$emit('revert')">{{ _('Revert') }}</f-button> <f-button secondary v-if="showRevert" @click="$emit('revert')">{{ _('Revert') }}</f-button>
<div class="ml-2" v-if="showPrint"> <div class="ml-2" v-if="showPrint">
@ -31,7 +36,7 @@ export default {
showNextAction: false, showNextAction: false,
showPrint: false, showPrint: false,
disableSave: false disableSave: false
} };
}, },
created() { created() {
this.doc.on('change', () => { this.doc.on('change', () => {
@ -44,36 +49,32 @@ export default {
this.isDirty = this.doc._dirty; this.isDirty = this.doc._dirty;
this.showSubmit = this.showSubmit =
this.meta.isSubmittable this.meta.isSubmittable &&
&& !this.isDirty !this.isDirty &&
&& !this.doc.isNew() !this.doc.isNew() &&
&& this.doc.submitted === 0; this.doc.submitted === 0;
this.showRevert = this.showRevert =
this.meta.isSubmittable this.meta.isSubmittable &&
&& !this.isDirty !this.isDirty &&
&& !this.doc.isNew() !this.doc.isNew() &&
&& this.doc.submitted === 1; this.doc.submitted === 1;
this.showNextAction = 1 this.showNextAction = 1;
this.showNextAction = this.showNextAction = !this.doc.isNew() && this.links.length;
!this.doc.isNew()
&& this.links.length;
this.showPrint = this.showPrint = this.doc.submitted === 1 && this.meta.print;
this.doc.submitted === 1
&& this.meta.print
this.showSave = this.showSave = this.doc.isNew()
this.doc.isNew() ? ? true
true : : this.meta.isSubmittable
this.meta.isSubmittable ? ? this.isDirty
(this.isDirty ? true : false) : ? true
true; : false
: true;
this.disableSave = this.disableSave = this.doc.isNew() ? false : !this.isDirty;
this.doc.isNew() ? false : !this.isDirty;
} }
}, },
computed: { computed: {
@ -84,12 +85,12 @@ export default {
const _ = this._; const _ = this._;
if (this.doc.isNew()) { if (this.doc.isNew()) {
return _('New {0}', _(this.doc.doctype)); return _('New {0}', _(this.meta.label || this.doc.doctype));
} }
const titleField = this.meta.titleField || 'name'; const titleField = this.meta.titleField || 'name';
return this.doc[titleField]; return this.doc[titleField];
} }
} }
} };
</script> </script>

View File

@ -2,19 +2,19 @@
<form :class="['frappe-form-layout', { 'was-validated': invalid }]"> <form :class="['frappe-form-layout', { 'was-validated': invalid }]">
<div <div
class="form-row" class="form-row"
v-if="layoutConfig" v-if="layoutConfig && showSection(i)"
v-for="(section, i) in layoutConfig.sections" v-for="(section, i) in layoutConfig.sections"
:key="i" :key="i"
v-show="showSection(i)"
> >
<div class="col" v-for="(column, j) in section.columns" :key="j"> <div class="col" v-for="(column, j) in section.columns" :key="j">
<frappe-control <frappe-control
v-for="fieldname in column.fields" v-for="(fieldname, k) in column.fields"
v-if="shouldRenderField(fieldname)" v-if="shouldRenderField(fieldname)"
:key="fieldname" :key="k"
:docfield="getDocField(fieldname)" :docfield="getDocField(fieldname)"
:value="$data[fieldname]" :value="$data[fieldname]"
:doc="doc" :doc="doc"
:autofocus="doc.isNew() && (i === currentSection || i === 0) && j === 0 && k === 0"
@change="value => updateDoc(fieldname, value)" @change="value => updateDoc(fieldname, value)"
/> />
</div> </div>

View File

@ -69,7 +69,7 @@
</table> </table>
<div class="table-actions" v-if="!disabled"> <div class="table-actions" v-if="!disabled">
<f-button danger @click="removeCheckedRows" v-if="checkedRows.length">Remove</f-button> <f-button danger @click="removeCheckedRows" v-if="checkedRows.length">Remove</f-button>
<f-button light @click="addRow" v-if="!checkedRows.length">Add Row</f-button> <f-button secondary @click="addRow" v-if="!checkedRows.length">Add Row</f-button>
</div> </div>
</div> </div>
</template> </template>
@ -100,7 +100,11 @@ export default {
const { index, fieldname } = this.currentlyFocused; const { index, fieldname } = this.currentlyFocused;
if (this.isEditing(index, fieldname)) { if (this.isEditing(index, fieldname)) {
// FIX: enter pressing on a cell with a value throws error. // FIX: enter pressing on a cell with a value throws error.
// this.deactivateEditing(); // Problem: input gets undefined on deactivating
setTimeout(() => {
this.deactivateEditing();
}, 300);
this.activateFocus(index, fieldname); this.activateFocus(index, fieldname);
} else { } else {
this.activateEditing(index, fieldname); this.activateEditing(index, fieldname);