4

Text area should not restrict to input unlimited character. But even i set empty in maximum length property of multiple text field, it took data-val-length-max="10000"? Can any one help asap to fix this?

  • 1
    Could you specify the version of WFFM? Might just need to adjust one of the specific .cshtml files in Views\Forms\EditorTemplates. – Jim Noellsch Dec 7 '16 at 20:39
2

Explanation

The following view is used for the Text Area: webroot\Views\Form\EditorTemplates\MultipleLineTextField.cshtml.

As I can see here it uses the Sitecore.Forms.Mvc.ViewModels.Fields.MultipleLineTextField model which is inherited from Sitecore.Forms.Mvc.ViewModels.Fields.SingleLineTextField.

This SingleLineTextField class has a property MaxLength with the DefaultValue(256).

public class SingleLineTextField : ValuedFieldViewModel<string>
{
    [DefaultValue(256)]
    public int MaxLength { get; set; }

    [DefaultValue(0)]
    public int MinLength { get; set; }

    [DynamicStringLength("MinLength", "MaxLength", ErrorMessage = "The field {0} must be a string with a minimum length of {1} and a maximum length of {2}.")]
    [DataType(DataType.Text)]
    public override string Value { get; set; }

    public override void Initialize()
    {
        if (this.MaxLength != 0)
        return;
        this.MaxLength = 256;
    }
}

That means you have to create your own model which does not have this MaxLength property.

Solution

Let's create your own model without maxlength.

using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using Sitecore.Forms.Mvc.Validators;
using Sitecore.Forms.Mvc.ViewModels;

namespace MyProject.Forms.Mvc.ViewModels.Fields
{
    public class MultipleLineTextFieldWithoutMax : ValuedFieldViewModel<string>
    {
        public int Rows { get; set; }

        public int Columns { get; set; }

        public override string ResultParameters
        {
            get
            {
                return "multipleline";
            }
        }

        [DefaultValue(0)]
        public int MinLength { get; set; }

        [DynamicStringLength("MinLength", "MaxLength", ErrorMessage = "The field {0} must be a string with a minimum length of {1}.")]
        [DataType(DataType.MultilineText)]
        public override string Value { get; set; }

        public MultipleLineTextFieldWithoutMax()
        {
            this.Rows = 4;
            this.Columns = 1;
        }
    }
}

Copy the webroot\Views\Form\EditorTemplates\MultipleLineTextField.cshtml view, let's call it MultipleLineTextFieldWithoutMax.cshtml

@using Sitecore.Forms.Mvc.Html
@model MyProject.Forms.Mvc.ViewModels.Fields.MultipleLineTextFieldWithoutMax

@using (Html.BeginField())
{
    @Html.TextAreaFor(x => Model.Value, Model.Rows, Model.Columns, new { @class = "form-control"})
}

Copy the /sitecore/system/Modules/Web Forms for Marketers/Settings/Field Types/Simple Types/Multiple-Line Text and use your new model there enter image description here

Be careful whenever you do an update because it can be changed!

The WFFM version in this solution is 8.1 rev 151217

| improve this answer | |
3

As you can see from the answer from @TRNKTMS the MaxLength property is of type int.

The easy solution is to set the Maximum Length to a (much) higher value, anything up to Int32.MaxValue, i.e. 2,147,483,647.

It's not strictly unlimited, but for a lot of practical purposes it is and should be more than sufficient...

But this is not a good idea though, you really don't want to set it that high.

Given that 1 ASCII character = 1 byte, therefore 2,147,483,647 characters of text = 2,147,483,647 bytes, or approx 2 GB of data. This is data that will have to be transferred from the client browser to the server, and then onto whatever storage systems, emails or whatever save actions you have configured.

Also bear in mind that <requestLimits maxAllowedContentLength in config is set to 500MB by default in Sitecore, you would also have to increase this value. I would recommend against this on a CD server for security reasons (and would highly recommend setting it to a much lower value on the CD servers anyway).

| improve this answer | |
  • True! I also would not really suggest to make this unlimited. – Tamás Tárnok Dec 8 '16 at 12:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.