- Status changed to Postponed
almost 2 years ago 12:17am 19 January 2023 - π«π·France prudloff Lille
Instead of implementing our own validation function, we might be able to simply add
#maxlength
to the field and letFormValidator::performRequiredValidation()
validate it: https://www.drupal.org/node/2887280 β - πͺπΈSpain albertosilva Basque Country
This patch adds
#maxlength
to the field, sotFormValidator::performRequiredValidation()
validates it, as proposed in #17. - π΅π±Poland gugalamaciek
#18 works, but it still won't allow to paste strings longer that
#maxlength
.On module configuration, I'd like to have these configuration options to define how limit should be treated:
- Allow input and saving of text that exceeds the specified limit. This option is available in current version of the module. It just displays information that you exceeded limit on edit form, but nothing more.
- Block input and saving of text that exceeds the set limit. This option is provided by patch #18. It's partially supported by hard limit option in current version of the module - the missing thing is to add validation during save. But #18 solves it.
- Allow adding text beyond the specified limit, but show an error message when attempting to save. This is the missing puzzle and most tricky one.
I analysed code of the module. I think that before we'll be able to implement last option, we have to refactor part of the module. The case it that
MaxLength
settings are defined on widget level. But, to implement last option, we have to add constraint on field level (to validate during save). So, all the configuration should be moved from widget level to field level. As example, see implementation of unique_field_ajax β module. It's very similar, but instead of validating length, it validates uniqueness.When I think more, it's also one more good reason to move configuration from widget to field level. If you configure things on that level, no matter which widget you select, they will be applied. You don't need to check widget type, it's enough to define field types that should be able use
MaxLength
feature. But what if I define my custom type in my module and I want to addMaxLength
to it? So this list should be alterable. Or... in admin/config create section forMaxLength
. And every webmaster will be able to decide for which field types module should be enabled. Also we can use plugin system and define something likeMaxLength
processors. That way any user can extend this module to it's custom field with custom processor to define how this should be validated.These are like ideas, how it can be implemented from my head, without deeper analysis. Also I don't have knowledge that inspired authors of the module to write it in a way that's written now. Some concepts might be to havy, some missing. But it sounds for me more like version 4.x of the module.