fix: validate hidden and mandatory fields without default in web form
This commit is contained in:
parent
1b81ff8490
commit
334d4d971f
2 changed files with 16 additions and 1 deletions
|
|
@ -161,7 +161,7 @@ export default class WebForm extends frappe.ui.FieldGroup {
|
||||||
let values = frappe.utils.get_query_params();
|
let values = frappe.utils.get_query_params();
|
||||||
delete values.new;
|
delete values.new;
|
||||||
Object.assign(defaults, values);
|
Object.assign(defaults, values);
|
||||||
this.set_values(values);
|
this.set_values(defaults);
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_primary_action() {
|
setup_primary_action() {
|
||||||
|
|
@ -226,6 +226,8 @@ export default class WebForm extends frappe.ui.FieldGroup {
|
||||||
field = this.fields_dict[fieldname];
|
field = this.fields_dict[fieldname];
|
||||||
|
|
||||||
if (field && field.get_value) {
|
if (field && field.get_value) {
|
||||||
|
if (field.df.hidden) continue;
|
||||||
|
|
||||||
let value = field.get_value();
|
let value = field.get_value();
|
||||||
if (
|
if (
|
||||||
field.df.reqd &&
|
field.df.reqd &&
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ from typing import Any
|
||||||
import frappe
|
import frappe
|
||||||
from frappe import _, scrub
|
from frappe import _, scrub
|
||||||
from frappe.core.api.file import get_max_file_size
|
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.core.doctype.file.utils import remove_file_by_url
|
||||||
from frappe.desk.form.meta import get_code_files_via_hooks
|
from frappe.desk.form.meta import get_code_files_via_hooks
|
||||||
from frappe.modules.utils import export_module_json, get_doc_module
|
from frappe.modules.utils import export_module_json, get_doc_module
|
||||||
|
|
@ -96,6 +97,8 @@ class WebForm(WebsiteGenerator):
|
||||||
if not frappe.flags.in_import:
|
if not frappe.flags.in_import:
|
||||||
self.validate_fields()
|
self.validate_fields()
|
||||||
|
|
||||||
|
self.validate_hidden_and_mandatory()
|
||||||
|
|
||||||
def validate_fields(self):
|
def validate_fields(self):
|
||||||
"""Validate all fields are present"""
|
"""Validate all fields are present"""
|
||||||
from frappe.model import no_value_fields
|
from frappe.model import no_value_fields
|
||||||
|
|
@ -110,6 +113,16 @@ class WebForm(WebsiteGenerator):
|
||||||
if missing:
|
if missing:
|
||||||
frappe.throw(_("Following fields are missing:") + "<br>" + "<br>".join(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):
|
def reset_field_parent(self):
|
||||||
"""Convert link fields to select with names as options."""
|
"""Convert link fields to select with names as options."""
|
||||||
for df in self.web_form_fields:
|
for df in self.web_form_fields:
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue