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

Validation error messages are not shown in the controlpanel #5274

Closed
wesleybl opened this issue Oct 4, 2023 · 7 comments · Fixed by #5950
Closed

Validation error messages are not shown in the controlpanel #5274

wesleybl opened this issue Oct 4, 2023 · 7 comments · Fixed by #5950
Assignees

Comments

@wesleybl
Copy link
Member

wesleybl commented Oct 4, 2023

Describe the bug
Validation error messages are not shown in any controlpanel. Either in those already existing in Plone or in new ones, added by products.

Response json example, when validation error occurs:

{
  "message": "Twitter username should not include the \"@\" prefix character.",
  "traceback": [
    "File \"/home/user/.buildout/eggs/cp310/Zope-5.8.3-py3.10.egg/ZPublisher/WSGIPublisher.py\", line 181, in transaction_pubevents",
    "    yield",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/Zope-5.8.3-py3.10.egg/ZPublisher/WSGIPublisher.py\", line 390, in publish_module",
    "    response = _publish(request, new_mod_info)",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/Zope-5.8.3-py3.10.egg/ZPublisher/WSGIPublisher.py\", line 285, in publish",
    "    result = mapply(obj,",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/Zope-5.8.3-py3.10.egg/ZPublisher/mapply.py\", line 85, in mapply",
    "    return debug(object, args, context)",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/Zope-5.8.3-py3.10.egg/ZPublisher/WSGIPublisher.py\", line 68, in call_object",
    "    return obj(*args)",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/plone.rest-3.0.0-py3.10.egg/plone/rest/service.py\", line 22, in __call__",
    "    return self.render()",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/plone.restapi-8.40.0-py3.10.egg/plone/restapi/services/__init__.py\", line 19, in render",
    "    content = self.reply()",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/plone.restapi-8.40.0-py3.10.egg/plone/restapi/services/controlpanels/update.py\", line 41, in reply",
    "    deserializer()  # The deserializer knows where to put it.",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/plone.restapi-8.40.0-py3.10.egg/plone/restapi/deserializer/controlpanels/__init__.py\", line 59, in __call__",
    "    value = deserializer(data[name])",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/plone.restapi-8.40.0-py3.10.egg/plone/restapi/deserializer/dxfields.py\", line 51, in __call__",
    "    value = IFromUnicode(self.field).fromUnicode(value)",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/zope.schema-7.0.1-py3.10.egg/zope/schema/_bootstrapfields.py\", line 556, in fromUnicode",
    "    self.validate(value)",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/zope.schema-7.0.1-py3.10.egg/zope/schema/_bootstrapfields.py\", line 295, in validate",
    "    self._validate(value)",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/zope.schema-7.0.1-py3.10.egg/zope/schema/_field.py\", line 211, in _validate",
    "    super(ASCII, self)._validate(value)",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/zope.schema-7.0.1-py3.10.egg/zope/schema/_bootstrapfields.py\", line 510, in _validate",
    "    super(MinMaxLen, self)._validate(value)",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/zope.schema-7.0.1-py3.10.egg/zope/schema/_bootstrapfields.py\", line 349, in _validate",
    "    constraint = self.constraint(value)",
    "",
    "  File \"/home/user/.buildout/eggs/cp310/plone.base-1.1.3-py3.10.egg/plone/base/interfaces/controlpanel.py\", line 1632, in validate_twitter_username",
    "    raise Invalid('Twitter username should not include the \"@\" prefix character.')"
  ],
  "type": "Invalid"
}

To Reproduce
Steps to reproduce the behavior:

  1. Go to Site Setup -> Social Media
  2. Fill in the Twitter username field with @test
  3. Click in Save
  4. No validation error message is displayed, although Twitter username cannot start with @

Expected behavior
Validation error message appears.

Screenshots
download (8)

Software (please complete the following information):

Volto 17.0.1
Plone 6.0.7
plone.restapi 8.43.1
CMF 3.2
Zope 5.8.5
Python 3.11.1 (main, Dec 7 2022, 01:11:34) [GCC 11.3.0]
PIL 9.5.0 (Pillow)

@avengsum
Copy link

avengsum commented Oct 9, 2023

@wesleybl I couldn't find where this code lies can you help me

@wesleybl
Copy link
Member Author

@avengsum the controlpanels form is here:

We would have to do something similar to what is done in the content editing form:

requestError={this.state.error}

It would be fantastic if you could fix this!

@abhinaisai2002
Copy link

How can we show the error messages like showing on a seperate modal or under the input itself

@wesleybl
Copy link
Member Author

@abhinaisai2002 If we are going to follow the way the content editing form does, we should show a modal at the end of the page. See:

download (1)

But it would be great to show the error in the field itself. But perhaps for this, it would be necessary to change the backend, to say in which field the error was.

But if we have the modal, it would be a step forward.

@davisagli
Copy link
Member

Don't use that toast message as an example, the backend is serializing validation errors incorrectly so they are not shown next to the field like they are supposed to be.

@wesleybl
Copy link
Member Author

Don't use that toast message as an example, the backend is serializing validation errors incorrectly so they are not shown next to the field like they are supposed to be.

@davisagli yes. But the controlpanel endpoint serializes in the same way. See the example in the issue description. So, for a fix without changing the backend, it would have to be the same way.

@wesleybl
Copy link
Member Author

wesleybl commented Mar 4, 2024

@avengsum @abhinaisai2002 would you be interested in fix this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants