Paragraphs validate that there are no errors before being saved.
paragraphs.field_widget.inc line 725

    // Only if the form is being submitted, finish the collection entity and
    // prepare it for saving.
    if ($form_state['submitted'] && !form_get_errors()) {

I have a case however where I disregard the errors using conditional fields and those fields are not paragraph attached.
Is there a way we would only check of errors related to paragraphs or some other smarter way of dealing with errors?

Comments

mihai_brb created an issue. See original summary.

jeroen.b’s picture

Status: Active » Postponed (maintainer needs more info)

How do you disregard errors? Maybe you can do this in a way that form_get_errors is still FALSE?

lennard westerveld’s picture

Status: Postponed (maintainer needs more info) » Closed (won't fix)

Collega of mine was having this same issue, its not related on paragraphs but related to conditional fields and how they handle errors and require fixes. See #2835827.

Sneakyvv’s picture

Title: Paragraph not saved on disregarded form errors » Paragraph not saved when error on untriggered conditional fields
Status: Closed (won't fix) » Needs review
StatusFileSize
new2.47 KB

Can I reopen this issue?

The situation is this:

  • Conditional fields checks if an untriggered field (e.g. a field that is not shown yet, since its dependee has not the right value) causes an error.
  • It keeps track of all such errors during the element-level validation. It does NOT remove the error at that point because that may cause collisions, as is stated in the comment in conditional_fields.module line 682:
      // Mark submitted values for removal. We have to remove them after all fields
      // have been validated to avoid collision between dependencies.
  • Then on form-level validation, conditional fields gets rid of these errors so the form validation & submission goes well.

Now, the problem is that paragraphs, also during the element-level validation, requires that there are no form errors, or it refuses to add the entity to the field value (form_state values). If the entity is not present (nor a 'value' entry), paragraphs_field_is_empty() will return TRUE (it is empty). This causes _field_filter_items(), which is being called from field_default_submit(), to remove the value from the element's values (in that function referred to as $items). So the paragraph field is now deleted/emptied.

So... Not really conditional fields' "fault". It can not remove the error on element-level validation, so it seems, and paragraphs will surely have a good reason to expect no errors on the whole form, before adding the entity (I did not look into that).

I have attached a patch which lets paragraphs check the errors conditional fields is keeping track of (the ones it will delete later on), and ignore those when making its decision to add the entity to the element values.

Sneakyvv’s picture

Sneakyvv’s picture

Version: 7.x-1.0-rc4 » 7.x-1.x-dev
Priority: Normal » Major

Hmm... I've updated the version to "latest dev", but it didn't apply. Trying again, now with comment...
Also bumping it up to major because the issue causes data loss.

Sneakyvv’s picture

StatusFileSize
new2.53 KB

The conditional_fields_untriggered_dependents key is apparently not always present in the $form_state and may thus cause undefined index notices. Patch updated.

aludescher’s picture

StatusFileSize
new2.61 KB

A minor change added to #7 to fix php notice and warning

Notice: Undefined index: errors in paragraphs_field_widget_embed_validate() (line 738 of .../paragraphs/paragraphs.field_widget.inc).
Warning: Invalid argument supplied for foreach() in paragraphs_field_widget_embed_validate() (line 738 of .../paragraphs/paragraphs.field_widget.inc).
donaldwbabcock’s picture

I hand applied the patch in #8 to paragraphs 7.x-1.0-rc5 and can confirm that the "not saved paragraphs" issue is no longer present.

works great for me.

donaldwbabcock’s picture

I should add that I've used CF and Paragraphs together before, and after looking into it on several of my sites, it is a combination of dependent required fields and paragraph that blows away paragraph content. It is not necessary that the required field be inside of or related to the paragraph in anyway.

To add to the description, the following are at least one of sets of steps to reproduce.
1. Install CF, Paragraphs
2. Create a node type with a required field that is conditional on another field. (my test had a required text field base on a select list controlling a type A vs type B option).
3. Add a paragraphs field to the node type.
4. create a new node with the condition where the required field stays hidden and is empty and then add a paragraph instance or two.

On save the node will be created, but the paragraphs will not be attached and will no longer exist. No messages of any kind are displayed.

Worse yet, changing an existing node that had a value in the required field to one that no longer displays that required field will remove all of the paragraphs, even the previously existing ones.

Follow the same above, one can avoid this problem by not having required fields be conditional.
Steps continuing from above:
5. remove the "required flag" from text field
6. repeat steps in step 4, everything will work as you might expect it to.

donaldwbabcock’s picture

Category: Feature request » Bug report

I don't think this is a feature request as it has the potential to cause content to be lost unexpectedly. Changing to bug report.

nbaosullivan’s picture

I can confirm applying patch #8 sorted my issue of Paragraph fields not saving when using Paragraphs (7.x-1.0-rc5) and Conditional Fields (7.x-3.0-alpha2).

Thanks very much!

Sneakyvv’s picture

Status: Needs review » Reviewed & tested by the community

I'd say that qualifies for RTBC.

capysara’s picture

The patch in #8 worked for me.

This issue also exists for field collection and there's some possibly relevant discussion in that thread regarding the order in which actions should occur, see #19 and and #52.

opgobee’s picture

The patch in #8 also worked for me.
Just as nbaosullivan I am using Paragraphs (7.x-1.0-rc5) and Conditional Fields (7.x-3.0-alpha2).

  • jstoller committed e685359 on 7.x-1.x authored by aludescher
    Issue #2609248 by Sneakyvv, aludescher, donaldwbabcock, nbaosullivan:...
jstoller’s picture

Status: Reviewed & tested by the community » Fixed

Patch committed to dev.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.