我可以增加 TextArea 组件中输入文本的最大长度吗?

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

我正在使用 Kentico 12 MVC and I'm working with the page builder

TextAreaComponent 有 500 个字符的限制。我想增加特定 属性 的限制或删除该验证规则并创建我自己的验证规则。这是因为我想将构建器用于长段落组件。这是 属性:

[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.";

我可以添加一个限制为 300 个字符的验证规则:

[StringLength(300)]

这会导致超过 300 个字符的验证错误:The field Text must be a string with a maximum length of 300.。当我超过 500 个字符时,它不会显示超过 300 个字符的验证错误,但会显示 500 个字符:Maximum allowed length of the input text is 500.

当我尝试将 StringLength 更改为超过 500 个时,表单构建器仍然在超过 500 个字符时显示相同的验证错误。设置 MaxLength 的方式相同。

我也尝试过扩展 TextAreaComponent 并实现我自己的价值 setter,但我不知道如何使用该自定义组件而不是本机 Kentico 组件。

如何增加限制 TextAreaComponent 值长度的验证规则?

每当创建 Kentico.Forms.Web.Mvc.TextAreaProperties 的新实例时,都会将硬编码的大小值 500 传递到基 class。

因此在您的自定义 TextAreaComponent 实现中,您可以尝试通过继承的 Properties 对象覆盖默认的 Size 值。

找一个合适的地方覆盖并尝试:

this.Properties.Size = 1000; // 或者任何适合你的东西

此处描述了注册自定义表单组件:https://docs.kentico.com/k12/developing-websites/form-builder-development/developing-custom-form-components

您还可以使用 EditingComponentProperty 属性设置大小,例如:

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

输入超过 500 个字符时的验证问题已在 12.0.26 中修复