Janneman96
Janneman96

Reputation: 505

Can I increase the maximum length of input text in the TextAreaComponent?

I'm using Kentico 12 MVC and I'm working with the page builder.

The TextAreaComponent has a limit for 500 characters. I would like to increase that limit for a specific property or remove that validation rule and create my own validation rules. This is because I'd like to use the builder for long paragraph components. This is the property:

[EditingComponent(TextAreaComponent.IDENTIFIER, Order = 0, Label = "Paragraaf")]
public string Text { get; set; } = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam bibendum sapien a justo dignissim pellentesque. Praesent rutrum venenatis neque in fringilla. Fusce vitae massa iaculis, mattis nulla vel, lacinia ex. Mauris sed dui ut nunc accumsan accumsan efficitur vel lacus. Morbi varius, libero et semper laoreet, arcu libero cursus purus, in congue est arcu eget nunc. Proin mattis justo at pharetra scelerisque. Pellentesque tristique elit odio, a bibendum dui laoreet sit amet. Cras orci ex, semper eget ipsum eget, molestie egestas urna. Maecenas vitae neque at nulla congue dictum. Vestibulum eu justo aliquet, feugiat elit at, consectetur mauris. Maecenas in neque dapibus, lacinia est at, laoreet nibh. Sed semper feugiat risus eu ultrices. Sed sagittis ut dolor nec aliquet.";

I can add a validation rule for a limit of 300 characters:

[StringLength(300)]

This results in a validation error above 300 characters: The field Text must be a string with a maximum length of 300.. When I go above 500 characters, it does not show the validation error for more than 300 characters, but it shows it for the 500 characters: Maximum allowed length of the input text is 500.

When I try to change StringLength to be more than 500, the form builders still shows the same validation error at more than 500 characters. Setting the MaxLength acts the same way.

I've also tried extending the TextAreaComponent and implementing my own value setter, but I don't know how I would use that custom component instead of the native Kentico component.

How do I increase the validation rule limiting the length of the TextAreaComponent value?

Upvotes: 0

Views: 970

Answers (3)

Peter
Peter

Reputation: 26

The validation issue when input was longer than 500 characters was fixed in 12.0.26

Upvotes: 0

zolex
zolex

Reputation: 106

You can also set the size by using the EditingComponentProperty attribute, for example:

[EditingComponentProperty("Size", 1000)]
[EditingComponent(TextAreaComponent.IDENTIFIER, Order = 0, Label = "Paragraaf")]
public string Text { get; set; }

Upvotes: 3

Dražen Janjiček
Dražen Janjiček

Reputation: 409

Whenever a new instance of Kentico.Forms.Web.Mvc.TextAreaProperties is created, a hardcoded Size value of 500 is passed into the base class.

So in your custom TextAreaComponent implementation, you can try to override the default Size value through the inherited Properties object.

Find an appropriate place to override and try:

this.Properties.Size = 1000; // Or whatever suits you

Registering the custom form component is described here: https://docs.kentico.com/k12/developing-websites/form-builder-development/developing-custom-form-components

Upvotes: 0

Related Questions