felixarntz / wpdlib

Common library for Definitely plugins for WordPress
GNU General Public License v3.0
3 stars 0 forks source link

Can't upload files when there are multiple media dialogues available on the same page #9

Open carlobeltrame opened 6 years ago

carlobeltrame commented 6 years ago

When adding a field of type 'media' to a cpt or option, we get a button which opens the inline WordPress media library dialogue. Changing the thumbnail of a post (or CPT, if it has thumbnail support) works through the same dialogue. This allows the user to select existing items from the media library, or upload new files.

However, as soon as there are multiple places on the same page that can open such a dialogue (e.g. edit CPT with two 'media' fields or with one 'media' field and thumbnail support), trying to upload a new file fails. In the Firefox debug console, the message TypeError: this.$index is undefined is displayed. In the Chromium debug console, the message is Uncaught TypeError: Cannot read property 'text' of undefined. Funnily enough, uploading via the built-in media -> new menu of WordPress still works.

A very similar bug has previously been described here and here. In that case it was an error caused by the combined use of two separate plugins. Both the workaround and the fix (proposed on the second page of the first link) were specific to those plugins, and can't be directly applied to the definitely plugins. One user identified the cause of the problem to be because a Javascript function called ready was never called (failing to set some properties that are needed later), although he did not find out why the function wasn't called.

carlobeltrame commented 6 years ago

Another field type that places a 'media' dialogue on the page is the 'wysiwyg' field type.