1. Create a content type
2. Add a Long text field with a Text area/Multiple rows widget
3. Use a WYSIWYG format
4. Add default data
5. Create a new node with CT
6. Delete default content
7. Save node
8. Deleted content is still there.

At this point, if one edits the node and then deletes the default content and saves, it is deleted.
Another note, if instead of deletion, one edits the default text, it is saved properly the first time (i.e. the original default text isn't reinserted).

This behavior may exist for other field types, just noticed it on the text field type at this time.

Comments

jastraat’s picture

Version: 7.0 » 7.4

Still an issue

I believe this is because _field_invoke_default() assumes that if a field is empty, the default needs to be added. This is great in the case of a pro-grammatically created node. However, if someone is adding a new node through the user interface, they will not be allowed to clear the default value for any field - even if it is not required.

fawzi’s picture

Title: Default value in text field is inserted on save even if deleted » Textfield always shows #default_value even no matter what the user enter in that textfield
Component: field system » forms system
Category: bug » support

hello ,

i have a form with 2 textfields within a fieldset. Both have some assigned #default_value. when i test the form, the first textfield would print out the content entered in that textfield correctly. However the second textfield would always print out the #default_value. No matter what i type in the form the valus is always the #default_value. I have no idea what is causing this. The two textfields are pretty much identical in all their attributes and location in the form.

any ideas would be great.. i wasted many hours on this issue...

thanks,

here is the code:
// Form Fieldset
$form['myFieldset'] = array(
'#title' => t('Pricelists Config Options'),
'#type' => 'fieldset',
'#prefix' => '

',
'#suffix' => '

',
'#collapsible' => TRUE,
'#collapsed' => TRUE,
);

//TextField 1
$form['myFieldset']['TextField_1'] = array(
'#title' => t('TextField 1),
'#type' => 'textfield',
'#required' => FALSE,
'#size' => 5,
'#maxlength' => 256,
'#weight' => $weight++,
'#default_value' => t('1.00'),
);

//TextField 2
$form['myFieldset']['TextField 2'] = array(
'#title' => t('TextField 2'),
'#type' => 'textfield',
'#required' => FALSE,
'#size' => 5,
'#maxlength' => 256,
'#weight' => $weight++,
'#default_value' => t('TextField 2'),
);

jastraat’s picture

Title: Textfield always shows #default_value even no matter what the user enter in that textfield » If a field has a default value, it cannot be empty on insert.
Component: forms system » field system
Category: support » bug

While you may have a support question, please don't override a core field issue.

fawzi’s picture

After many attempts i figured out what was causing the problem.

if you look at my naming, i had an underscore in the 1st, and a space in the 2nd.
Changing:
$form['myFieldset']['TextField 2'] to $form['myFieldset']['TextField_2']

Moreover, i found out that periods in a name do not work either so ['U.S. drupal'] and ['U.S._drupal'] would fail while ['US_drupal'] would not.

i am not sure what you want to do with this or where the fix should be, but it seems that it is an error for me that needs fixing...

thanks,

Fawzi

tim.plunkett’s picture

Status: Active » Closed (works as designed)

Unfortunately, there is no way to know if that field was supposed to retain its value, or if it was truly representing the default. If the behavior were to change, it would be confusing and data-destructive.

Jon Betts’s picture

Hmmm...I would think that by deleting the data, I'm letting it know that the data shouldn't be there.

yched’s picture

Status: Closed (works as designed) » Closed (duplicate)

This is an actual bug, dupe of #1253820: It's impossible to submit no value for a field that has a default value. That other thread is newer, but gathered more insight.