I would rewrite _maxlength_format_element to remove drupal_add_js settings.

I think the bevahior of maxlength should be attached to the formelement directly.
This would have quite some advantages:

much less arguments in this function
easier to handle for other forms, comments...contact etc.

new paramater: $js = TRUE

But:
_maxlength_get_values should be remove and be there as parameter

Perhaps put the validate stuff in another validate function, perhaps could be possible to use form_set_error, not sure.

Any opinions.

Comments

giorgio79’s picture

+1
This would be fantastic.

I would be happy to test.

This would also enable this #550956: Programmatically set maxlength for given field

hefox’s picture

Status: Active » Closed (duplicate)

Patch that basically covers this in #984794: Create API for non-node forms. _maxlength_get_values is still there, but only being used to get the values to set in the element. (Duplicating this one instead of that one cause posted patch in that one XD).