2
0
mirror of https://github.com/frappe/books.git synced 2024-12-23 03:19:01 +00:00

validate child table mandatory

This commit is contained in:
Rushabh Mehta 2018-02-12 15:12:26 +05:30
parent 3af4fb8671
commit 95cbd8ea61
3 changed files with 39 additions and 2 deletions

View File

@ -12,11 +12,13 @@ html {
.main {
border-left: 1px solid $gray-300;
min-height: calc(100vh - 50px);
}
.sidebar {
.list-group-item {
padding: $spacer-2 $spacer-3;
border: none;
}
.list-group-flush {

View File

@ -72,6 +72,7 @@ class TableControl extends BaseControl {
return {
initValue: (value, rowIndex, column) => {
column.activeControl = control;
control.parent_control = this;
control.doc = this.doc[this.fieldname][rowIndex];
control.set_focus();
@ -134,11 +135,29 @@ class TableControl extends BaseControl {
return [];
}
if (!this.doc[this.fieldname]) {
this.doc[this.fieldname] = [{}];
this.doc[this.fieldname] = [{idx: 0}];
}
return this.doc[this.fieldname];
}
checkValidity() {
let data = this.getTableData();
for (let rowIndex=0; rowIndex < data.length; rowIndex++) {
let row = data[rowIndex];
for (let column of this.datatable.datamanager.columns) {
if (column.field && column.field.required) {
let value = row[column.field.fieldname];
if (value==='' || value===undefined || value===null) {
let $cell = this.datatable.cellmanager.getCell$(column.colIndex, rowIndex);
this.datatable.cellmanager.activateEditing($cell);
return false;
}
}
}
}
return true;
}
};
module.exports = TableControl;

View File

@ -84,8 +84,24 @@ module.exports = class BaseForm extends Observable {
});
}
checkValidity() {
let validity = this.form.checkValidity();
if (validity) {
for (let control of this.controlList) {
// check validity in table
if (control.fieldtype==='Table') {
validity = control.checkValidity();
if (!validity) {
break;
}
}
}
}
return validity;
}
async submit() {
if (!this.form.checkValidity()) {
if (!this.checkValidity()) {
this.form.classList.add('was-validated');
return;
}