Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: multistep webform page navigation #26172

Merged
merged 1 commit into from Apr 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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