Correct way to add className to textarea

Correct way to add className to textarea

sitesurfersitesurfer Posts: 34Questions: 9Answers: 0

Hi all.

I am playing with the Bootstrap 3 Editor and have discovered that the textareas need styling:

Currently I note that adding className : "form-control" to the init results in the div that Editor constructs taking that class.

                           "label": "Mapping Requirements",
            "name": "ppp_projects.proj_mapping_needs",
            "type": "textarea",
            "className": "form-control"

As a workaround I am setting a delay after 'open' and adding the class manually to the named fields directly using JQuery - obviously this is a labour intensive process with multiple text areas.

setTimeout(function(){
//set the class here
},500);

Is this is the pipe line to be fixed - or do I carry on with my kludge?

Oo

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,528Questions: 1Answers: 10,473 Site admin
    Answer ✓

    The textarea field type has an attr option which is used to apply attributes to the element. So what you could do is:

    "label": "Mapping Requirements",
    "name": "ppp_projects.proj_mapping_needs",
    "type": "textarea",
    "attr": {
      "class": "form-control"
    }
    

    The other option is to use the field().node() method immediately after the initialisation and add the required class there: $( 'textarea', editor.field( 'myField' ).node() ).addClass( 'form-control' );.

    Allan

  • sitesurfersitesurfer Posts: 34Questions: 9Answers: 0

    Ooooh thanks!

    That was peachy!

    Oo

This discussion has been closed.