Can two Data Types placed on the same doctypes have properites with the same ID?

I am developing a large package for Umbraco and it will have mutiple properties that you could create data types off of. There is slight overlap between funcality of two properties but because you can chose to ahve one, the other, or both of the properties the overlap needs to exist. In this case it is a check box to enbable a flag. The check box has the exact same function in both properties so I was going to give them the same ID. What whould the potental problems be when I inspect that checkbox ID in the notificaiton handler during an ContentPublishingNotification?

Hi @Eaglef90

No, you can’t have two properties with the same ID (alias) on a document type. If you try and do this through the UI (and presumably through the API) it will fail validation or you will get an error. This include document types that use compositions or inheritance.

Justin

Maybe I am not using property in the right context here, honistly it seems umbraco interchanges a LOT of terminology all over the place and it is confusing. As I am not talking about the property at the Data Type high level property that you add into a document type. I mean a form element of a property.

In my case my plug-in has two different properties (each one a seperate property you could build a new data type off of) one property generates 2 text boxes and a check box. The other preropty generates a dropdown list and a checkbox. In the Render() call of the element.ts file for each property I use the uui-checkbox tag to display the checkboxes, in that tag I set the id to the same value. So like each propertie’s element.ts file has

<uui-checkbox id=”myCheckBox”></uui-checkbox>

It’s not even an Umbraco thing, you should only have one element on your page with the same ID - they should be unique. It won’t break anything but it is best practice. I’m assuming here that the ID in the UUI tag just transposes directly to the HTML output without being modified.

I think you mean that you have two Property Editors. Property Editors are what you create Data Types for. A Data Type is an instance of a Property Editor + Configuration. When you add a Property to a Document Type, you select the Data Type on the property.

So far I don’t feel like Umbraco uses terminology all over the place. But I’m happy to clarify terminology for you if needed :slight_smile:

I know best HTML practice is not to have identical IDs, and in my case I can control that, but I also can’t control what other package devlopers give as IDs to there input elements. My question originaly came from wanting to use the same ID on two boxes since they have the same function, then I remmeberd the name property and can just use that. So now my curiousity comes from what happens if two packages have input elements of the same ID? When a doucment is saved how does umbraco deal with that?

To be honest, I don’t know - it should use the name property when submitting a save/publish so ID won’t matter. But what happens when there are duplicate name properties I’m not sure. I guess one will win but which one I don’t know. Sorry if that doesn’t really help!

@Eaglef90 I think it depends which “ID” you mean.

If you mean the Document Type property alias, then no, those must be unique on the same Document Type/composition.

If you mean a configuration property alias inside two different Property Editor/Data Type setups, reusing the same alias for the same setting is fine. It is scoped to that editor/config collection, e.g. both editors can read:

const enableFlag = config.getValueByAlias(‘enableFlag’);

Just don’t duplicate aliases within the same settings.properties collection.

If you mean an actual HTML id on a checkbox, I’d avoid depending on that being globally unique. Bind to the element/event instead, or generate a unique id per component instance if you need label for="...".