locked
TextAreaFor Auto row RRS feed

  • Question

  • User1670624291 posted

    Hi,

    I have a text area that adjusts to the number of lines in the content. I currently have a function that whenever I write it increases the line but when I save it it goes back to two lines.
    I wanted him to adapt the number of lines to the text because i have foreach, how can I solve this?

    @foreach (var item4 in item2.status)
    {
     @Html.TextAreaFor(m => @item4.Obs, new { @class = "Obs form-control form-control-sm font-weight-bold", disabled = true, style = "width: 400px;", rows = "auto", oninput = "auto_grow(this)" })
    }
     function auto_grow(element) {
                element.style.height = "5px";
                element.style.height = (element.scrollHeight) + "px";
            }

    Friday, March 12, 2021 9:46 AM

Answers

  • User-474980206 posted

    If using jquery, use $.ready() to run the auto grow function on each text area.

    $(function(){
         $(“textarea.Obs”).each(function() {
               auto_grow(this);
          });
    });

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, March 12, 2021 3:37 PM