MaxLength API Not Working

Created on 27 March 2023, almost 2 years ago

Problem/Motivation

Adding Maxlength to my custom form is not working

Steps to reproduce

I added

'#description' => $this->t("My title."),
            '#maxlength_js' => TRUE,
            '#attributes' => [
              'data-maxlength' => 62,
              'maxlength_js_label' => $this->t('@remaining characters left.'),
            ],

To my form field. It shows up on my form, and even counts down as I type. However if I go over my limit the counter goes negative. I can still save the form and the entire string is saved no matter how long.

Any idea what could be wrong here?

πŸ’¬ Support request
Status

Closed: works as designed

Version

2.1

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States stevenpatz Alexandria VA

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @stevenpatz
  • πŸ‡ΊπŸ‡ΈUnited States stevenpatz Alexandria VA

    Looks like if I add '#maxlength_js_enforce' => TRUE, to my field's attributes it works.

  • Status changed to Closed: works as designed almost 2 years ago
  • πŸ‡ΊπŸ‡ΈUnited States cedewey Denver, CO

    Looks like you got it sorted out. Thanks for using the module and reach out again if you run into any further questions or issues. Thanks!

Production build 0.71.5 2024