Topic: MDB Bootstrap Support

NitinMistry free asked 5 years ago


Hi,

I am facing problem with character counter in dynamically added textarea component. I'm using version 4.6.0 (not available in the version selection dropdown).

var inp = $("<div class='md-form'>\
<textarea id='" + idName + qNo + "' class='authoring md-textarea' length='256'></textarea>\
<label for='" + idName + qNo + "'>Question text</label>\
</div>")

inp.appendTo($("#MyDiv"));

$("input#"idName+qNo, "textarea#"idName+qNo).characterCounter();

 

The component is properly added to the DOM as I inspect it in the component inspecter panel in Chrome dev tools. Even after initializing the characterCounter() method after adding the component to "MyDiv" I don't get the character counter. However, if I copy/paste the code of the component (by replacing dynamic variables with static text for IDs), the character counter appears.

The span for characterCounter is added to DOM only when the code is written statically in the HTML but there is no span tag when the code is dynamically added via JS.

Can you please help?


NitinMistry free answered 5 years ago


Thank Jakub. It worked perfectly fine. I guess I missed adding the 'form-control' class as well as the rows attribute to the tag.


Jakub Mandra staff answered 5 years ago


Hi,

I corrected your code and it looks like it works ok.
Can you check out this snippet?

You can fork it and make your changes.



Please insert min. 20 characters.

FREE CONSULTATION

Hire our experts to build a dedicated project. We'll analyze your business requirements, for free.

Status

Resolved

Specification of the issue

  • ForumUser: Free
  • Premium support: No
  • Technology: MDB jQuery
  • MDB Version: 4.5.15
  • Device: Desktop
  • Browser: Chrome 71.0.3578.98 (64-bit)
  • OS: Windows 8.1
  • Provided sample code: Yes
  • Provided link: No