Skip to content

Commit

Permalink
Merge pull request #26218 from frappe/mergify/bp/version-15-hotfix/pr…
Browse files Browse the repository at this point in the history
…-26172

fix: multistep webform page navigation (backport #26172)
  • Loading branch information
rutwikhdev committed Apr 29, 2024
2 parents 2f171cd + 9415f4f commit 31450c7
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions frappe/public/js/frappe/web_form/web_form.js
Expand Up @@ -195,7 +195,7 @@ export default class WebForm extends frappe.ui.FieldGroup {
validate_section() {
if (this.allow_incomplete) return true;

let fields = $(`.form-page:eq(${this.current_section}) .form-control`);
let fields = $(`${this.get_page(this.current_section)} .form-control`);
let errors = [];
let invalid_values = [];

Expand All @@ -205,7 +205,7 @@ export default class WebForm extends frappe.ui.FieldGroup {

field = this.fields_dict[fieldname];

if (field.get_value) {
if (field && field.get_value) {
let value = field.get_value();
if (
field.df.reqd &&
Expand Down Expand Up @@ -306,17 +306,17 @@ export default class WebForm extends frappe.ui.FieldGroup {
is_next_section_empty(section) {
if (section + 1 > this.page_breaks.length + 1) return true;

let _section = $(`.form-page:eq(${section + 1})`);
let visible_controls = _section.find(".frappe-control:not(.hide-control)");
let _page = $(`${this.get_page(section + 1)}`);
let visible_controls = _page.find(".frappe-control:not(.hide-control)");

return !visible_controls.length ? true : false;
}

is_previous_section_empty(section) {
if (section - 1 > this.page_breaks.length + 1) return true;

let _section = $(`.form-page:eq(${section - 1})`);
let visible_controls = _section.find(".frappe-control:not(.hide-control)");
let _page = $(`${this.get_page(section - 1)}`);
let visible_controls = _page.find(".frappe-control:not(.hide-control)");

return !visible_controls.length ? true : false;
}
Expand All @@ -335,14 +335,18 @@ export default class WebForm extends frappe.ui.FieldGroup {
this.current_section == 0 ? $(".btn-previous").hide() : $(".btn-previous").show();
}

get_page(idx) {
return idx > 0 ? `.page-break:eq(${idx - 1})` : `.form-page:eq(${idx})`;
}

show_form_page() {
$(`.form-page:eq(${this.current_section})`).show();
$(this.get_page(this.current_section)).show();
}

hide_form_pages() {
for (let idx = 0; idx <= this.page_breaks.length; idx++) {
if (idx !== this.current_section) {
$(`.form-page:eq(${idx})`).hide();
$(this.get_page(idx)).hide();
}
}
}
Expand Down

0 comments on commit 31450c7

Please sign in to comment.