Problem/Motivation

Basically return event.preventDefault(); when event is not set at all (called from detach behavior in editor module application.js)

Steps to reproduce

Submit h5p form with empty main title using AJAX.

Proposed resolution

See the attached patch.

Remaining tasks

This is more a workaround or a quick fix to prevent data loss, this should be addressed properly at some point. I found this that could help:
https://drupal.stackexchange.com/questions/271808/how-to-prevent-an-ajax...

CommentFileSizeAuthor
#2 h5p-3281356-2.patch1.38 KBgraber

Issue fork h5p-3281356

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

Graber created an issue. See original summary.

graber’s picture

StatusFileSize
new1.38 KB
graber’s picture

Status: Active » Needs review
alexrayu’s picture

Status: Needs review » Reviewed & tested by the community

Confirmed. This patch successfully substitutes a title.

sim_1’s picture

Status: Reviewed & tested by the community » Needs work

This works to substitute a title, but I still end up in a bad state. The form validation works when creating the H5P is in a unique form, but when it's within a multi-value field it fails. For example, we have it as a media item that can be added in a multi-value field and that submit/save button (for the field) isn't recognized in the same was as the whole entity submit button.

sim_1’s picture

Is there a better way to detect what type of form (single value field form within a node vs media vs multivalue field etc) it is and therefore intercept the form validation more universally there?

maya maier’s picture

Do you have repro steps/configuration for this issue? I'm unclear on the context where this would be submitted through AJAX.

sim_1’s picture

Yes, this particularly happens when H5Ps are being added within a multi-value field. This means that the field to add an h5p exists within a node/entity form. The node validation and the h5p form validation aren't speaking well to each other.

msandoval made their first commit to this issue’s fork.

msandoval’s picture

Assigned: graber » Unassigned
Status: Needs work » Needs review

I've applied changes to the submit handler to account for use in multi-value fields. Ready for review.

illeace’s picture

Version: 2.0.0-alpha2 » 2.0.x-dev
Status: Needs review » Reviewed & tested by the community

With this fix, we've somewhat redefined the issue being fixed, which is that any unsaved H5P edits are lost when adding or removing an H5P field in the multi-H5P field scenario. This patch largely fixes that and is a meaningful enough improvement that I'm marking it RTBC, despite the fact that there is still a fair amount of jank in the validation of H5P items, especially in a multi-field environment. Some examples of remaining issues:

  • #3216239: Can't save host entity after adding more while using H5P Editor when missing required fields
  • In single-value H5P fields, clicking Save twice bypasses H5P validation.
  • In multi-value fields during AJAX rebuild (adding/removing an H5P field) unsaved changes are lost if those changes aren't valid (e.g., try adding a period to the "Word list" field in a "Find the words" H5P, then click the "Add another item" button).
  • On Chrome browser, you are able to save empty, required H5P fields when you have two "Multiple Choice" items.

I think the interaction between Drupal form validation and H5P item/field validation needs a bit of a refactor. I will create a new issue along those lines and include this detail in that issue.

sim_1’s picture

I think the original issue I was concerned with was #3216239: Can't save host entity after adding more while using H5P Editor when missing required fields. I wasn't aware of this other one. I will merge this issue, but I guess it's important to note for others looking for a fix, that my comments above apply to that other issue, not the one that was solved here.

  • sim_1 committed e3590ece on 2.0.x authored by msandoval
    [#3281356] fix: Main title validation not working on AJAX detach leading...
sim_1’s picture

Status: Reviewed & tested by the community » Fixed

Merged and marking as fixed. Thank you, everyone!

Now that this issue is closed, please review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, please credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

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