Skip to content

Validation messages do not display correctly with Bootstrap 4 #431

@stevepiercy

Description

@stevepiercy

Bootstrap 4 made changes to the validation messages from Bootstrap 3. The migration guide notes:

  • Replaced .has-error, .has-warning, and .has-success classes with HTML5 form validation via CSS’s :invalid and :valid pseudo-classes.

For Deform this means:

  • Change default error_class from error to invalid-feedback.
  • Add a class is-invalid to the HTML input. Note that both this and the previous must be done jointly in order for the error message to appear.
  • Replace a few instances of has-error with is-invalid.
  • Replace a few instances of <p class="help-block" with <div class="form-text invalid-feedback" as well as the closing tag. See https://getbootstrap.com/docs/4.5/components/forms/#help-text
  • Update tests in both Deform and deformdemo to detect the proper CSS class.

Examples

deform/templates/mapping_item.pt

class="form-group ${field.error and 'is-invalid' or ''} ${field.widget.item_css_class or ''} ${field.default_item_css_class()}"
...
<div class="invalid-feedback"
...
</div>

deform/templates/textinput.pt

error_class error_class|field.widget.error_class;
...
tal:attributes="class string: form-control ${css_class or ''} ${field.error and error_class or ''};

See also https://getbootstrap.com/docs/4.5/components/forms/?#validation, and in particular https://getbootstrap.com/docs/4.5/components/forms/?#server-side

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions