Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display error for required fields without value in current language #2314

Merged
merged 3 commits into from
May 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.5.0 (unreleased)
------------------

- #2314 Display error for required fields without value in current language
- #2313 Log error when calculation fails
- #2310 Added `get_relative_delta` and `get_tzinfo` in datetime API
- #2311 Properly process and validate field values from sample header on submit
Expand Down
31 changes: 29 additions & 2 deletions src/bika/lims/browser/analysisrequest/add2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from plone.memoize.volatile import DontCache
from plone.memoize.volatile import cache
from plone.protect.interfaces import IDisableCSRFProtection
from Products.Archetypes.interfaces import IField
from Products.CMFPlone.utils import safe_unicode
from Products.Five.browser import BrowserView
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
Expand All @@ -52,6 +53,7 @@
from zope.component import getAdapters
from zope.component import queryAdapter
from zope.i18n.locales import locales
from zope.i18nmessageid import Message
from zope.interface import alsoProvides
from zope.interface import implements
from zope.publisher.interfaces import IPublishTraverse
Expand Down Expand Up @@ -1557,6 +1559,30 @@ def ajax_recalculate_prices(self):

return prices

def get_field(self, field_name):
"""Returns the field from the temporary sample with the given name
"""
if IField.providedBy(field_name):
return field_name

for field in self.get_ar_fields():
if field.getName() == field_name:
return field
return None

def get_field_label(self, field):
"""Returns the translated label of the given field
"""
field = self.get_field(field)
if not field:
return ""

instance = self.get_ar()
label = field.widget.Label(instance)
if isinstance(label, Message):
return self.context.translate(label)
return label

def check_confirmation(self):
"""Returns a dict when user confirmation is required for the creation of
samples. Returns None otherwise
Expand Down Expand Up @@ -1701,8 +1727,9 @@ def ajax_submit(self):
# If there are required fields missing, flag an error
for field in missing:
fieldname = "{}-{}".format(field, num)
msg = _("Field '{}' is required").format(safe_unicode(field))
fielderrors[fieldname] = msg
label = self.get_field_label(field)
msg = self.context.translate(_("Field '{}' is required"))
fielderrors[fieldname] = msg.format(label)

# Process and validate field values
valid_record = dict()
Expand Down