Przeglądaj źródła

[minor] validate web form and upload in customize form

version-14
Rushabh Mehta 8 lat temu
rodzic
commit
b79dfe9970
4 zmienionych plików z 30 dodań i 6 usunięć
  1. +3
    -0
      frappe/custom/doctype/customize_form/customize_form.js
  2. +8
    -6
      frappe/custom/doctype/customize_form/customize_form.py
  3. +5
    -0
      frappe/public/js/frappe/form/grid.js
  4. +14
    -0
      frappe/website/doctype/web_form/web_form.py

+ 3
- 0
frappe/custom/doctype/customize_form/customize_form.js Wyświetl plik

@@ -4,6 +4,9 @@
frappe.provide("frappe.customize_form");

frappe.ui.form.on("Customize Form", {
setup: function(frm) {
frm.get_docfield("fields").allow_bulk_edit = 1;
},
onload: function(frm) {
frappe.customize_form.add_fields_help(frm);



+ 8
- 6
frappe/custom/doctype/customize_form/customize_form.py Wyświetl plik

@@ -195,10 +195,11 @@ class CustomizeForm(Document):

def update_custom_fields(self):
for i, df in enumerate(self.get("fields")):
if df.get("__islocal"):
self.add_custom_field(df, i)
else:
self.update_in_custom_field(df, i)
if df.get("is_custom_field"):
if not frappe.db.exists('Custom Field', {'dt': self.doc_type, 'fieldname': df.fieldname}):
self.add_custom_field(df, i)
else:
self.update_in_custom_field(df, i)

self.delete_custom_fields()

@@ -209,8 +210,8 @@ class CustomizeForm(Document):

for property in docfield_properties:
d.set(property, df.get(property))
if i!=0:
if i!=0:
d.insert_after = self.fields[i-1].fieldname
d.idx = i

@@ -221,6 +222,7 @@ class CustomizeForm(Document):
meta = frappe.get_meta(self.doc_type)
meta_df = meta.get("fields", {"fieldname": df.fieldname})
if not (meta_df and meta_df[0].get("is_custom_field")):
# not a custom field
return

custom_field = frappe.get_doc("Custom Field", meta_df[0].name)


+ 5
- 0
frappe/public/js/frappe/form/grid.js Wyświetl plik

@@ -460,6 +460,11 @@ frappe.ui.form.Grid = Class.extend({
if(df.fieldtype==="Date" && value) {
value = frappe.datetime.user_to_str(value);
}

if(df.fieldtype==="Int" || df.fieldtype==="Check") {
value = cint(value);
}

d[fieldnames[ci]] = value;
});
}


+ 14
- 0
frappe/website/doctype/web_form/web_form.py Wyświetl plik

@@ -36,6 +36,20 @@ class WebForm(WebsiteGenerator):
and self.is_standard and not frappe.conf.developer_mode):
frappe.throw(_("You need to be in developer mode to edit a Standard Web Form"))

self.validate_fields()

def validate_fields(self):
'''Validate all fields are present'''
from frappe.model import no_value_fields
missing = []
meta = frappe.get_meta(self.doc_type)
for df in self.web_form_fields:
if df.fieldname and (df.fieldtype not in no_value_fields and not meta.has_field(df.fieldname)):
missing.append(df.fieldname)

if missing:
frappe.throw(_('Following fields are missing:') + '<br>' + '<br>'.join(missing))

def reset_field_parent(self):
'''Convert link fields to select with names as options'''
for df in self.web_form_fields:


Ładowanie…
Anuluj
Zapisz