Skip to content

Commit

Permalink
Skip validating non-required fields
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffersonBledsoe committed Mar 19, 2024
1 parent 77bd00b commit 30a619d
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import re
from typing import Any

from collective.volto.formsupport.validation import getValidations

Expand Down Expand Up @@ -30,7 +31,7 @@ def value_is_not(value, target_value):


class Field:
def __init__(self, field_data):
def __init__(self, field_data: dict[str, Any]):
def _attribute(attribute_name: str):
setattr(self, attribute_name, field_data.get(attribute_name))

Expand All @@ -40,11 +41,11 @@ def _attribute(attribute_name: str):
_attribute("show_when_is")
_attribute("show_when_to")
_attribute("input_values")
_attribute("required")
_attribute("widget")
_attribute("use_as_reply_to")
_attribute("use_as_reply_bcc")
_attribute("validations")
self.required = field_data.get("required")
self.validations = field_data.get("validations")
self._display_value_mapping = field_data.get("dislpay_value_mapping")
self._value = field_data.get("value", "")
self._custom_field_id = field_data.get("custom_field_id")
Expand All @@ -62,7 +63,7 @@ def value(self, value):
self._value = value

def should_show(self, show_when_is, target_value):
always_show_validator = show_when_validators['always']
always_show_validator = show_when_validators["always"]
if not show_when_is:
return always_show_validator()
show_when_validator = show_when_validators[show_when_is]
Expand Down Expand Up @@ -94,6 +95,8 @@ def send_in_email(self):

def validate(self):
# Making sure we've got a validation that actually exists.
if not self._value and not self.required:
breakpoint()
available_validations = [
validation
for validationId, validation in getValidations()
Expand Down

0 comments on commit 30a619d

Please sign in to comment.