Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

how to validate in assets dam properties?

amangoyal15
Level 3
Level 3

I need to validate in asset dam properties.

I took reference from https://helpx.adobe.com/experience-manager/using/creating-touchui-validate.html 

 

Code Snippet - 

$(document).on("click", ".aem-assets-admin-properties-submit", function (e) {

        e.stopPropagation();
        e.preventDefault();
      ddlOrderValue = $("#ddlChar option:selected").val();

    if(typeof ddlOrderValue == "string" && typeof primaryBVTag == "string" && typeof primarySLTag == "string"){
          var ddlOrderValueCheck  = ddlOrderValue.substring(ddlOrderValue.lastIndexOf("/")+1);
          var primaryBVTagCheck  = primaryBVTag.substring(primaryBVTag.lastIndexOf("/")+1);
          var primarySLTagCheck  = primarySLTag.substring(primarySLTag.lastIndexOf("/")+1);
      }


        if( (($('#setcontentownerid').hasClass("hide")) == false ) && (ddlOrderValueCheck == '') || ( primaryBVTagCheck == '' &&  primarySLTagCheck == '') ||             ((ddlOrderValueCheck != primaryBVTagCheck) && (ddlOrderValueCheck != primarySLTagCheck)) ) {
                alert("Check your Inputs");
              ns.ui.helpers.prompt({
                title: Granite.I18n.get("Invalid Input"),
                message: "Please Enter valid Inputs",
                actions: [{
                    id: "CANCEL",
                    text: "CANCEL",
                    className: "coral-Button"
                }],
            callback: function (actionId) {
                if (actionId === "CANCEL") {
                }
            }
        });

        }else{
            alert("else");

                createNewTags($(".data-fields.active form")).done(function(){
                var form = $('.data-fields.active form');
                alert("else aem-submit -createNewTags");
                handleResponse(form, submitForm(form));
            }).fail(function(response){
                var modal = $('#aem-assets-metadataedit-error');
                var body = Granite.I18n.get('Unable to create new tags. Check for access privileges to create tags.');
                modal.find(".coral-Modal-body").html('<p>' + body + '</p>');
                modal.modal("show");
            });
            alert("end of else");
          }

    }); 


// -----------------------------------------------------------------------------------------------------------------------   
    function createNewTags (form) {
        return $.when.apply(null, form.find('[data-metatype="tags"].coral-PathBrowser+ul.coral-TagList input[type="hidden"][name]').map(function() {
            var el = this;

            if (el.value.indexOf(":") >= 0) return;

            var tenantId = $(".foundation-form.mode-edit").attr("tenant-id");
            el.value = tenantId ? ("mac:" + tenantId + "/default/" + el.previousElementSibling.textContent ) : el.previousElementSibling.textContent;
            return createSingleTag(el.value).then(function(tag) {
                // Fix tag name in select element
                var tenantId = $(".foundation-form.mode-edit").attr("tenant-id");
                if (!tenantId) {
                    // Fix tag name in select element
                    el.value = tag;
                }
            });
        }));
    }

I am getting error because of ns.ui.helper.prompt({     });  , error in browser console is -

Uncaught TypeError: Cannot read property 'ui' of undefined
    at HTMLButtonElement.<anonymous> (clientlib-assetspropertiesdialog.js:287)
    at HTMLDocument.dispatch (jquery.js:4665)
    at HTMLDocument.elemData.handle (jquery.js:4333)

4 Replies
kautuk_sahni
Community Manager
Community Manager

Hi

Moving this post to AEM "Assets" topic so that contextual experts can help you.

~kautuk

smacdonald2008
Level 10
Level 10

The article you mentioned is about how to validate fields in a component dialog.  Has nothing to do with Assets.

Karanjeet_Singh
Level 2
Level 2

Can you make sure "ns" is defined? Or can you share the complete code?