Hello,

I have been reading the discussion at http://drupal.org/node/81297, and found it very interesting. Especially the details about the addition of the '#wysiwyg' attribute.

I have a form that contains multiple textareas, and currently the wysiwyg.module is applying editors to all of them, so I plan to use the '#wysiwyg' attribute to over come this.

Is there a way to disable multiple textareas without having to code specific cases for each field?

So instead of :
$form[textarea-1][#wysiwyg] = false;
$form[textarea-2][#wysiwyg] = false;
... etc

Can I do something like:
$form[field-type][textarea][#wysiwyg] = false;

Any help would be great.

Comments

sun’s picture

Status: Active » Fixed

Unfortunately, no. You would have to use element_children($form) to iterate over all form fields (recursively). I would be interested in everything you come up with.

Also, there is no setting to switch the overall default value of #wysiwyg to FALSE, so you could selectively set it to TRUE on certain fields only. I think this would be valuable to have, but requires a lot of consideration and development.

emTque’s picture

Status: Fixed » Needs work

i have made a little headway with this, but it is not working completely.

i used the form_alter hook in one of my contrib modules to iterate through the form fields as you suggested with the following code:

foreach (element_children($form) as $key) { 
      if($form[$key]['#type'] == 'textarea') {
        $form[$key]['#wysiwyg'] = FALSE;
      }
      else {
        // recurse through all children
        mycontribmodule_form_alter($form_id, $form[$key]); 
      }   
    }

this was based on the form_alter i found in "jscalendar.module".

i then created a white-list of textareas where i wanted the wysiwyg editor, using the $form array:

$form['body_filter']['body']['#wysiwyg'] = TRUE;  

this worked fine for every field except those that are added by the Workflow module. it seems that these are added after my form_alter is finished with the $form array, so i can't target them.

any suggestions??

sun’s picture

Status: Needs work » Active

Yes, that's possible. You need to increase the weight of your module to a value that is higher than the weight of workflow module. Module weights are stored in the 'system' database table.

emTque’s picture

YES!!!

thanks sun!!!

that worked and now my forms are working fine. thanks for your help.

sun’s picture

Title: Multiple textareas in one form » HowTo: Customize multiple textareas in one form

Better title to not screw other users away.

sun’s picture

Status: Active » Closed (duplicate)