TextArea weird behaviour when clearing

1 Answer 248 Views
TextArea
Daniel
Top achievements
Rank 1
Iron
Daniel asked on 13 Apr 2023, 01:15 AM

Hi,

We've initialised a TextArea using the following code:

$("#textArea").kendoTextArea({
	label: "Label",
	rows: 4,
	maxLength: 1000
});

And try to clear it using the following code:

const textArea = $("#textArea").kendoTextArea().data("kendoTextArea");
textArea.value("");
textArea.trigger("change");

It works but it looks like it resets any configuration you set like rows and maxLength and adds extra markup.

Here's the markup before the clear:

<span class="k-input k-textarea k-input-solid k-input-md k-rounded-md k-resize-none" style=""><textarea id="textbox-notes" data-role="textarea" aria-disabled="false" maxlength="1000" rows="4" class="!k-overflow-y-auto k-input-inner" autocomplete="off" style="width: 100%; resize: none;"></textarea></span>

And after:

<span class="k-input k-textarea k-input-solid k-input-md k-rounded-md k-resize-none" style=""><span class="k-input k-textarea !k-overflow-y-auto k-input-inner k-input-solid k-input-md k-rounded-md k-resize-none" style="width: 100%; resize: none;"><textarea id="textbox-notes" data-role="textarea" aria-disabled="false" rows="1" class="!k-overflow-y-auto k-input-inner" autocomplete="off" style="width: 100%; resize: none;"></textarea></span></span>

Note the rows have reset to 1 and maxlength is missing. Also, there is an extra SPAN around the original SPAN and TEXTAREA. We tried setting the properties manually after the change trigger using:

$("#textArea").prop("rows", "4");
$("#textArea").prop("maxlength", "1000");

This works okay but obviously doesn't fix the extra markup.

Is this the correct way to clear a TextArea? Or do we just reset the value in jQuery directly?

Thanks

 

 

 

1 Answer, 1 is accepted

Sort by
0
Martin
Telerik team
answered on 17 Apr 2023, 02:16 PM

Hello, Daniel,

The coloured part from the line below initializes the TextArea widget anew and therefore resets what configurations you have. 

const textArea = $("#textArea").kendoTextArea().data("kendoTextArea");

If you remove that part, you will get a reference to the already existing component, and proceed with the code to clear its value.

Let me know how the above works for you.

Regards,
Martin
Progress Telerik

Love the Telerik and Kendo UI products and believe more people should try them? Invite a fellow developer to become a Progress customer and each of you can get a $50 Amazon gift voucher.

Daniel
Top achievements
Rank 1
Iron
commented on 17 Apr 2023, 10:09 PM

Thanks that works.
Tags
TextArea
Asked by
Daniel
Top achievements
Rank 1
Iron
Answers by
Martin
Telerik team
Share this question
or