Skip to content

Commit

Permalink
validate each step of setup wizard before next
Browse files Browse the repository at this point in the history
  • Loading branch information
netchampfaris committed Apr 2, 2018
1 parent e4dd0a9 commit 56aa6c7
Show file tree
Hide file tree
Showing 5 changed files with 8,832 additions and 8,315 deletions.
15 changes: 0 additions & 15 deletions models/doctype/AccountingSettings/AccountingSettings.js
Expand Up @@ -23,14 +23,6 @@ module.exports = {
fieldtype: "Account"
},

{
"fieldname": "file",
"label": "File",
"fieldtype": "Data",
"required": 1,
"directory": 1
},

{
"fieldname": "country",
"label": "Country",
Expand All @@ -53,13 +45,6 @@ module.exports = {
"required": 1
},

{
"fieldname": "abbreviation",
"label": "Abbreviation",
"fieldtype": "Data",
"required": 1
},

{
"fieldname": "bankName",
"label": "Bank Name",
Expand Down
19 changes: 3 additions & 16 deletions setup/config.js
Expand Up @@ -30,7 +30,8 @@ module.exports = {
"fieldname": "email",
"label": "Email",
"fieldtype": "Data",
"required": 1
"required": 1,
"inputType": "email"
},

{
Expand All @@ -40,13 +41,6 @@ module.exports = {
"required": 1
},

{
"fieldname": "abbreviation",
"label": "Abbreviation",
"fieldtype": "Data",
"required": 1
},

{
"fieldname": "bankName",
"label": "Bank Name",
Expand All @@ -73,14 +67,7 @@ module.exports = {

{
title: 'Add your Company',
columns: [
{
fields: ['companyName', 'bankName']
},
{
fields: ['abbreviation']
},
]
fields: ['companyName', 'bankName']
}
]
}
24 changes: 23 additions & 1 deletion setup/index.js
Expand Up @@ -89,7 +89,29 @@ module.exports = class SetupWizard {
}

nextSlide() {
this.showSlide(this.currentIndex + 1);
const isValid = this.validateCurrentSlide();
frappe.ui.toggleClass(this.formLayout.sections[this.currentIndex], 'was-validated', !isValid);

if (isValid) {
this.showSlide(this.currentIndex + 1);
}
}

validateCurrentSlide() {
const fields = this.getFieldsInSlide(this.currentIndex);
const inputValidityMap = fields.map(field => this.formLayout.controls[field].input.checkValidity());
const isValid = !inputValidityMap.includes(false);
return isValid;
}

getFieldsInSlide(index) {
const visibleSection = slideConfigs.layout[index];
const fieldsInSlide = visibleSection.fields ||
visibleSection.columns.reduce(
(col, fields) => fields.concat(col.fields), []
);

return fieldsInSlide;
}

activateIndicator(index) {
Expand Down
2 changes: 2 additions & 0 deletions www/dist/css/style.css
Expand Up @@ -7587,3 +7587,5 @@ input[type=file] {
overflow: hidden;
position: absolute;
z-index: -1; }
.was-validated input[type=file]:invalid + button {
border-color: #dc3545; }

0 comments on commit 56aa6c7

Please sign in to comment.