fix: validate hidden and mandatory fields without default in web form

This commit is contained in:
Kaushal Shriwas 2026-04-11 16:57:02 +05:30
parent 1b81ff8490
commit 334d4d971f
2 changed files with 16 additions and 1 deletions

View file

@ -161,7 +161,7 @@ export default class WebForm extends frappe.ui.FieldGroup {
let values = frappe.utils.get_query_params();
delete values.new;
Object.assign(defaults, values);
this.set_values(values);
this.set_values(defaults);
}
setup_primary_action() {
@ -226,6 +226,8 @@ export default class WebForm extends frappe.ui.FieldGroup {
field = this.fields_dict[fieldname];
if (field && field.get_value) {
if (field.df.hidden) continue;
let value = field.get_value();
if (
field.df.reqd &&

View file

@ -8,6 +8,7 @@ from typing import Any
import frappe
from frappe import _, scrub
from frappe.core.api.file import get_max_file_size
from frappe.core.doctype.doctype.doctype import HiddenAndMandatoryWithoutDefaultError
from frappe.core.doctype.file.utils import remove_file_by_url
from frappe.desk.form.meta import get_code_files_via_hooks
from frappe.modules.utils import export_module_json, get_doc_module
@ -96,6 +97,8 @@ class WebForm(WebsiteGenerator):
if not frappe.flags.in_import:
self.validate_fields()
self.validate_hidden_and_mandatory()
def validate_fields(self):
"""Validate all fields are present"""
from frappe.model import no_value_fields
@ -110,6 +113,16 @@ class WebForm(WebsiteGenerator):
if missing:
frappe.throw(_("Following fields are missing:") + "<br>" + "<br>".join(missing))
def validate_hidden_and_mandatory(self):
for d in self.web_form_fields:
if d.hidden and d.reqd and not d.default and not frappe.flags.in_migrate:
frappe.throw(
_("{0}: Field {1} in row {2} cannot be hidden and mandatory without default").format(
self.name, d.label, d.idx
),
HiddenAndMandatoryWithoutDefaultError,
)
def reset_field_parent(self):
"""Convert link fields to select with names as options."""
for df in self.web_form_fields: