When I wrote the patch for #2763505: Move file_entity and file_browser's Field Widget for Files and Images to Entity Browser, I didn't realize that #limit_validation_errors works as a whitelist of form elements to validate, and would remove form state if left empty. As a result, if you click "Remove" right now when using the FileBrowserWidget, it wipes form state (essentially removing all elements).

What I really wanted was to ignore validation errors if the Remove button was clicked, which this patch should do. The flagErrors() logic is copied from core's FileWidget class.

Comments

samuel.mortenson created an issue. See original summary.

slashrsm’s picture

Issue tags: +D8Media
StatusFileSize
new1.32 KB
new1.09 KB

What about this solution? This will only validate target_id, since it is needed by the remove button. That might work as it will prevent alt, title, description, ... form being validated.

There is errorElement() on parent class which seems to be trying to achieve something similar. I think that it would make sense to solve this in there if possible.

samuel.mortenson’s picture

Status: Needs review » Reviewed & tested by the community

Nice, this is working well from my manual testing with File Browser. Thanks @slashrm!

slashrsm’s picture

Status: Reviewed & tested by the community » Fixed

Great! Committed.

Status: Fixed » Closed (fixed)

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