Skip to content

Show validation error message ?! #69

@lksnmnn

Description

@lksnmnn

Hey there,

thank you for this extension and example on how to extend the core form elements.
I've added this element to form and configured it to be "required". The form can't be submitted, if the checkbox is not checked. However, it does not render any error message?!

The yaml of the element:

     -
        type: Fieldset
        identifier: fieldset-privacy
        label: Datenschutz
        renderables:
          -
            properties:
              pageUid: '149'
              linkText: Datenschutz
              additionalLinks:
                150: 'Code of Conduct'
              fluidAdditionalAttributes:
                required: required
              validationErrorMessages:
                -
                  code: 1221560910
                  message: 'Bitte geben Sie Ihr Einverständnis zur Kontaktaufnahme.'
                -
                  code: 1221560718
                  message: 'Bitte geben Sie Ihr Einverständnis zur Kontaktaufnahme.'
                -
                  code: 1347992400
                  message: 'Bitte geben Sie Ihr Einverständnis zur Kontaktaufnahme.'
                -
                  code: 1347992453
                  message: 'Bitte geben Sie Ihr Einverständnis zur Kontaktaufnahme.'
            type: LinkedCheckbox
            identifier: checkbox-privacy-conduct
            label: 'Ja, ich habe die Hinweise zum %s und zum %s gelesen und erkläre mich einverstanden, dass meine Daten zur Kontaktaufnahme verwendet werden dürfen.'
            validators:
              -
                identifier: NotEmpty

I am using Typo3 12.4.14

When I override the partial as follows (merged with FrontendVersion2 checkbox partial), the error messages work:

<html xmlns:f="http://typo3.org/ns/TYPO3/CMS/Fluid/ViewHelpers" xmlns:formvh="http://typo3.org/ns/TYPO3/CMS/Form/ViewHelpers" data-namespace-typo3-fluid="true">
<formvh:renderRenderable renderable="{element}">
  <f:form.validationResults for="{element.rootForm.identifier}.{element.identifier}">
    <f:if condition="{element.properties.elementDescription}">
        <f:variable name="aria" value="{describedby: '{element.uniqueIdentifier}-desc'}" />
    </f:if>
    <f:if condition="{validationResults.errors}">
        <f:variable name="aria" value="{invalid: 'true', describedby: '{element.uniqueIdentifier}-errors'}" />
    </f:if>
    <f:variable name="errorClass">{f:if(condition: '{validationResults.errors}', then: ' {element.rootForm.renderingOptions.fieldProperties.errorClassAttribute}')}</f:variable>

    <f:render partial="Field/Field" arguments="{element: element, doNotShowLabel: 1}" contentAs="elementContent">
      <label class="form-check form-check-label {element.properties.labelClassAttribute}{errorClass}" for="{element.uniqueIdentifier}">
        <f:form.checkbox
          property="{element.identifier}"
          id="{element.uniqueIdentifier}"
          class="{element.properties.elementClassAttribute}"
          value="{element.properties.value}"
          errorClass="{element.rootForm.renderingOptions.fieldProperties.errorClassAttribute}"
          additionalAttributes="{formvh:translateElementProperty(element: element, property: 'fluidAdditionalAttributes')}"
          aria="{aria}"
          />
          <span class="{element.properties.labelTextClassAttribute}">{formvh:translateElementProperty(element: element, property: 'label') -> f:format.stripTags(allowedTags: '<a>')}<f:if condition="{element.required}"><f:render partial="Field/Required" /></f:if></span>
      </label>
    </f:render>
  </f:form.validationResults>
</formvh:renderRenderable>
</html>

If you wish I can create a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions