JavaScript for WordPress Forums Bugs & Issues Broken gallery block – Advanced Gutenberg Course

This topic contains 3 replies, has 2 voices, and was last updated by  ldecoker 1 month ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #90077

    ldecoker
    Participant

    Hello!

    When I tried to add multiple pictures in the gallery block, I got a JS error:

    Uncaught (in promise) TypeError: Cannot read property 'large' of undefined

    To be more precise, when click on Media Library, it’s working, not when using the Upload button.
    If I check the content of the newImages variable, I can indeed see that it does only take the first selected picture.

    When editing the gallery, it does include all pictures from my media library to the gallery.

    Thx!

    • This topic was modified 1 month, 1 week ago by  ldecoker.
    #90559

    ldecoker
    Participant

    Hello!

    The errors I’ve got came from this code (from github):

    const onSelectImages = newImages => {
          const images = newImages.map(img =>
            Object.assign(
              {},
              {
                src: img.sizes.large.url,
                width: img.sizes.large.width,
                height: img.sizes.large.height,
                id: img.sizes.large.id,
                alt: img.sizes.large.alt,
                caption: img.sizes.large.caption
              }
            )
          );
          setAttributes({ images });
        };

    First I had to change large by full and then for the id/alt/caption field, you need to remove the sizes.large part.

    Have a nice day!

    #90592

    Zac Gordon
    Keymaster

    Thanks for sharing!

    Our of curiosity, what were the sizes of the images you were using?

    #90795

    ldecoker
    Participant

    Hello!

    I used the ones from your advanced course.

    Have a nice day!

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.