Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Charlene 10 posts 78 karma points
    Sep 29, 2021 @ 13:58
    Charlene
    0

    Drag and drop Media doesn't ask for the required field.

    I have edited the Image data type to have a mandatory field called 'title'. When the media is created using the create Button - It asks for the title field.

    enter image description here enter image description here

    However - if the drag and drop functionality is used - It uploads the image without validating the required title field.

    Is there a way to make sure the image always validates the required fields?

  • MK 429 posts 906 karma points
    Nov 21, 2022 @ 10:12
    MK
    0

    Hi Charlene,

    Did you manage to sort this out?

    Thanks

    mk

  • MK 429 posts 906 karma points
    Nov 29, 2022 @ 06:43
    MK
    0

    Hi, I did the following. You can alter this as per your requirements.

    app.run(function (eventsService, mediaResource, editorService) {
        var unsubscribe = eventsService.on("dialogs.mediaPicker.select", function (event, args) {
            mediaResource.getById(args.id).then(function (mediaEntity) {
                const propNotValid = mediaEntity.properties.some(function (element) {
                    return element.validation.mandatory === true && element.value === '';
                });
                if (propNotValid) {
                    const mediaEditor = {
                        id: args.id,
                        submit: () => {
                            editorService.close();
                        },
                        close: () => {
                            editorService.close();
                        }
                    };
                    editorService.mediaEditor(mediaEditor);
                }
            });
        });
    });
    

    mk

  • YuQing Zhang 7 posts 28 karma points
    Sep 19, 2023 @ 04:01
    YuQing Zhang
    0

    Hi MK,

    How can I inject the code you posted above?

    /Yuqing

  • MK 429 posts 906 karma points
    Sep 19, 2023 @ 08:19
    MK
    0

    Hi YuQing, you can add a custom prop to your page. Also checkout this doc: https://docs.umbraco.com/umbraco-cms/reference/angular/services/eventsservice mk

Please Sign in or register to post replies

Write your reply to:

Draft