Highlighted

Get the default value for an element's attribute

Adobe Community Professional ,
Jun 22, 2018

Copy link to clipboard

Copied

I use this to get an attribute value that is assigned to a particular element:

var version = getAttributeValue (element, "TemplateVersion");

alert (version);

function getAttributeValue (element, name) {

   

    var attrList = element.Attributes, i = 0;

    for (i = 0; i < attrList.length; i += 1) {

        if (attrList.name === name) {

            if (attrList.values[0]) {

                return (attrList.values[0]);

            }

            else {

                // If the attribute exists, but doesn't have a value, return an empty string.

                return "";

            }

        }

    }  // If the attribute doesn't exist, return undefined.

}

In this particular case, TemplateVersion is read-only and is assigned in the EDD as a default value. When I use the function above, it returns a blank string because the value has been set as a default and not explicitly set. How can I return the default value of the attribute? Thank you very much.

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

OK, I get it. I have to go through the element's ElementDef (element definition) property:

var version = getDefaultAttributeValue (element, "TemplateVersion");

alert (version);

function getDefaultAttributeValue (element, name) {

   

    var elementDef, attributeDefs, i;

   

    elementDef = element.ElementDef;

    attributeDefs = elementDef.AttributeDefs;

    for (i = 0; i < attributeDefs.length; i += 1) {

        if (attributeDefs.name === name) {

            return (attributeDefs.defValues[0]);

        }

    }

}

TOPICS
Scripting

Views

303

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

Get the default value for an element's attribute

Adobe Community Professional ,
Jun 22, 2018

Copy link to clipboard

Copied

I use this to get an attribute value that is assigned to a particular element:

var version = getAttributeValue (element, "TemplateVersion");

alert (version);

function getAttributeValue (element, name) {

   

    var attrList = element.Attributes, i = 0;

    for (i = 0; i < attrList.length; i += 1) {

        if (attrList.name === name) {

            if (attrList.values[0]) {

                return (attrList.values[0]);

            }

            else {

                // If the attribute exists, but doesn't have a value, return an empty string.

                return "";

            }

        }

    }  // If the attribute doesn't exist, return undefined.

}

In this particular case, TemplateVersion is read-only and is assigned in the EDD as a default value. When I use the function above, it returns a blank string because the value has been set as a default and not explicitly set. How can I return the default value of the attribute? Thank you very much.

Adobe Community Professional
Correct answer by frameexpert | Adobe Community Professional

OK, I get it. I have to go through the element's ElementDef (element definition) property:

var version = getDefaultAttributeValue (element, "TemplateVersion");

alert (version);

function getDefaultAttributeValue (element, name) {

   

    var elementDef, attributeDefs, i;

   

    elementDef = element.ElementDef;

    attributeDefs = elementDef.AttributeDefs;

    for (i = 0; i < attributeDefs.length; i += 1) {

        if (attributeDefs.name === name) {

            return (attributeDefs.defValues[0]);

        }

    }

}

TOPICS
Scripting

Views

304

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jun 22, 2018 0
Adobe Community Professional ,
Jun 22, 2018

Copy link to clipboard

Copied

OK, I get it. I have to go through the element's ElementDef (element definition) property:

var version = getDefaultAttributeValue (element, "TemplateVersion");

alert (version);

function getDefaultAttributeValue (element, name) {

   

    var elementDef, attributeDefs, i;

   

    elementDef = element.ElementDef;

    attributeDefs = elementDef.AttributeDefs;

    for (i = 0; i < attributeDefs.length; i += 1) {

        if (attributeDefs.name === name) {

            return (attributeDefs.defValues[0]);

        }

    }

}

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 22, 2018 0
Advocate ,
Jun 22, 2018

Copy link to clipboard

Copied

Hi Rick,

I was digging up some old dusty scripts as I remembered I have done this. Yes, that was the trick. The element definition has all the default settings.

Glad you figured it out. There is a LOT of dust on those old scripts. 🙂

Ciao

Jang

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jun 22, 2018 0