default settings cause empty values to be saved for plain-text fields

leeksoup - October 21, 2007 - 22:45
Project:Whizzywig
Version:5.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:sdecabooter
Status:closed
Description

By default, the module is enabled for all textareas, even those associated with plain text fields, i.e. custom fields that do not support HTML formatting.

I found when testing this module that when editing a content type with such a field, every time I edit and save, an additional three empty values are saved for the field. For example, if the field is "Notes", then the dev load after one edit / save cycle might look like this:

field_notes

Array
(
    [0] => Array
        (
            [value] => Copyrights 2002/2006
        )

    [1] => Array
        (
            [value] =>
        )

    [2] => Array
        (
            [value] =>
        )
    [3] => Array
        (
            [value] =>
        )
)

This problem goes away if I do not allow the whizzywig editing for this field.

Is it possible to check for the field type and disallow if it is a plain text field? Otherwise, documenting this will be helpful.

#1

sdecabooter - October 22, 2007 - 12:27

I suppose you are talking about CCK fields?
I don't think there's a way to check if a text field is supposed to be plain text or not.

I do know that the Whizzywig module hasn't been tested thoroughly with CCK fields yet.
I'll try to reproduce your problem and come up with a solution (it might take a while... i'm rather busy right now)

Thanks for reporting.

#2

sdecabooter - October 22, 2007 - 12:28
Assigned to:Anonymous» sdecabooter

#3

leeksoup - October 22, 2007 - 21:28

Yes, it is a CCK field. In fact most of my DB consists of custom content types built with CCK.

This info (i.e. whether the field is plain text or HTML) must be availabe somewhere otherwise the edit widget would not "know" whether to include the "input format" dropdown or not. Unfortunately, I don't know exactly where.

Thanks for looking into it.

#4

sdecabooter - October 23, 2007 - 15:17

Is this fixed by the changes you suggested in this comment: http://drupal.org/node/179496#comment-326078 ?

#5

leeksoup - October 23, 2007 - 21:02

No. The two are completely unrelated.

I would guess that the problem above is caused by whizzywig returning some non-empty value for the additional fields in the edit form. These then get saved.

OK, I did a bit of digging and find that it (whizzywig) returns some kind of newline character at the beginning of every field for which it is enabled, even when the user leaves the field empty. This character is what causes the "empty" field values to be saved.

#6

leeksoup - October 23, 2007 - 22:40

I found this info while searching for something else. I hope it helps.

If you want to find out the "type" of a field, you can do:

$field = content_fields ('<field_name>');
// At this point, $field[type] will be "text" for a text field
// and $field[text_processing] will tell you whether it is a plain text field (0)

#7

leeksoup - October 29, 2007 - 21:27

It would be very nice to check the type of text fields and automatically disable whizzywig for plain text fields, but meanwhile users can just disable it for those fields manually by using the feature to enable / disable for listed form IDs. The fix in http://drupal.org/node/179496 may be needed for this workaround to work correctly.

#8

sdecabooter - November 7, 2007 - 15:19

Hi leeksoup,

I tried implementing a check for the CCK fields.
Partly based on the code you provided, it checks whether
- a textarea is a CCK textfield
- if so, if it's plaintext or rich text

If it turns out to be plaintext, the editor is not loaded.

I updated the code for the -dev release to support this. Can you run some tests if this fixes your issue (and does not create new issues :p) ?

Thanks

#9

leeksoup - November 14, 2007 - 00:30

Hi Sven,

I am busy right now getting other things fixed on my site but I hope to check out your fix within the week.

Thanks for implementing!

#10

drupal-id.com - October 24, 2009 - 02:18
Status:active» closed

Whizzywig version 6.x supports enable/disable editor for certain TEXTAREA ID. You can enable/disable editor for certain CCK textarea field.

Please upgrade to Drupal 6 and use Whizzywig 6.x version, thanks.

 
 

Drupal is a registered trademark of Dries Buytaert.