Add custom form field wrapper to determine if form data has changes

This commit is contained in:
Patrick Smith
2019-01-31 14:01:55 -05:00
parent 843645122a
commit 6fe9229f89
2 changed files with 48 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
from wtforms.fields import Field, StringField, SelectField as SelectField_
from wtforms.fields import Field, FormField, StringField, SelectField as SelectField_
from wtforms.widgets import TextArea
@@ -39,3 +39,14 @@ class NumberStringField(StringField):
self.data = str(value)
else:
self.data = value
class FormFieldWrapper(FormField):
def has_changes(self):
if not self.object_data:
return False
for (attr, field) in self._fields.items():
if attr in self.object_data and self.object_data[attr] != field.data:
return True
return False