Skip to content

Commit

Permalink
fixed form.vars misbehavior
Browse files Browse the repository at this point in the history
  • Loading branch information
mdipierro committed Aug 6, 2023
1 parent 021a357 commit a984f1f
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions py4web/utils/form.py
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,6 @@ def __init__(
self.vars.update(validated_vars)
if dbio:
self.update_or_insert(validated_vars)
self.clear()
elif dbio:
self.deleted = True
self.record.delete_record()
Expand Down Expand Up @@ -919,21 +918,24 @@ def update_or_insert(self, validated_vars):
# warning, should we really insert if record
self.vars["id"] = self.table.insert(**validated_vars)

def clear(self):
self.errors.clear()
def clear(self, vars, errors):
errors.clear()
if not self.record and not self.keep_values:
self.vars.clear()
vars.clear()
for field in self.table:
self.vars[field.name] = (
vars[field.name] = (
field.default() if callable(field.default) else field.default
)

def helper(self):
vars, errors = copy.copy(self.vars), copy.copy(self.errors)
if self.accepted:
self.clear(vars, errors)
if not self.cached_helper:
helper = self.param.formstyle(
self.table,
self.vars,
self.errors,
vars,
errors,
self.readonly,
self.deletable,
self.noncreate,
Expand Down

0 comments on commit a984f1f

Please sign in to comment.