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?
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | paragraphs-check_CF_errors-2609248-8.patch | 2.61 KB | aludescher |
| #7 | paragraphs-check_CF_errors-2609248-7.patch | 2.53 KB | Sneakyvv |
Comments
Comment #2
jeroen.b commentedHow do you disregard errors? Maybe you can do this in a way that form_get_errors is still FALSE?
Comment #3
lennard westerveldCollega 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.
Comment #4
Sneakyvv commentedCan I reopen this issue?
The situation is this:
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.
Comment #5
Sneakyvv commentedComment #6
Sneakyvv commentedHmm... 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.
Comment #7
Sneakyvv commentedThe conditional_fields_untriggered_dependents key is apparently not always present in the $form_state and may thus cause undefined index notices. Patch updated.
Comment #8
aludescher commentedA minor change added to #7 to fix php notice and warning
Comment #9
donaldwbabcock commentedI 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.
Comment #10
donaldwbabcock commentedI 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.
Comment #11
donaldwbabcock commentedI don't think this is a feature request as it has the potential to cause content to be lost unexpectedly. Changing to bug report.
Comment #12
nbaosullivan commentedI 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!
Comment #13
Sneakyvv commentedI'd say that qualifies for RTBC.
Comment #14
capysara commentedThe 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.
Comment #15
opgobee commentedThe 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).
Comment #17
jstollerPatch committed to dev.