I am working on creating a custom data type in Umbraco 4.5.2, following the tutorial at http://www.nibble.be/?p=50.
I have managed to get everything setup and can use the new datatype. However, I cannot figure out how to load the existing property value for the document to use in the DataEditor. The tutorial above uses the following method to get the data:
public override IData Data
{
get
{
if (baseData == null)
{
baseData = new umbraco.cms.businesslogic.datatype.DefaultData(this);
}
return baseData;
}
}
But this will load the default data, not what is saved with the associated document.
I know I could get the property off the current document based on the data type id of my custom data type, but that approach would break down if I had more than one property using my custom data type for a given document type. Any suggestions? I am new to umbraco, so I am hoping I am missing something obvious.
When you publish is the value of your new Data type being saved? You can check by opening the to the /App_data/umbraco.config file and searching for the name you gave the new data type property.
Yes, the new value for the property is being saved, I checked the config file you mentioned and the database.
However, if I leave the document node that I was editing and then come back to it, the 'default' value for the datatype is what gets loaded for property. I cannot figure out a way to tell the dataeditor to load the existing property value.
I must be missing something. Hopefully you can clear things up for me.
I followed the same approach as outlined in the tutorial I refeneced above. _data is a private member of type IData in my DataEditor class. _data gets set in the constructor of my DataEditor to a value that is passed to the constructor. The constructor is called by my DataType class. In my DataType class, the IData object that gets passed to the constructor of my DataEditor is defined as follows:
publicoverride umbraco.interfaces.IData Data
{
get
{
if (_baseData == null)
_baseData = new umbraco.cms.businesslogic.datatype.DefaultData(this);
return _baseData;
}
}
When I use this approach, my property always gets assigned null. That is probably because the DefaultData for my DataType is null, which makes sense I suppose. I did check to make sure that when I enter a new value for the property and save the document that the value does get saved to both the DataBase and the umbraco.config file.
I do not understand how the existing value of a property on a specific document that uses my custom DataType is retrieved from the Umbraco database.
Load exisiting data in custom datatype?
I am working on creating a custom data type in Umbraco 4.5.2, following the tutorial at http://www.nibble.be/?p=50.
I have managed to get everything setup and can use the new datatype. However, I cannot figure out how to load the existing property value for the document to use in the DataEditor. The tutorial above uses the following method to get the data:
public override IData Data { get { if (baseData == null) { baseData = new umbraco.cms.businesslogic.datatype.DefaultData(this); } return baseData; } }
But this will load the default data, not what is saved with the associated document.
I know I could get the property off the current document based on the data type id of my custom data type, but that approach would break down if I had more than one property using my custom data type for a given document type. Any suggestions? I am new to umbraco, so I am hoping I am missing something obvious.
Hi Jon,
When you publish is the value of your new Data type being saved? You can check by opening the to the /App_data/umbraco.config file and searching for the name you gave the new data type property.
Neil
Yes, the new value for the property is being saved, I checked the config file you mentioned and the database.
However, if I leave the document node that I was editing and then come back to it, the 'default' value for the datatype is what gets loaded for property. I cannot figure out a way to tell the dataeditor to load the existing property value.
Does anyone have any suggestions?
Hi Jon,
You need to set the value of your textbox or other control using _data.Value (from Tim's example)
txtCharLimit.Text = _data.Value.ToString();
-Tom
Thanks for the reply Tom,
I must be missing something. Hopefully you can clear things up for me.
I followed the same approach as outlined in the tutorial I refeneced above. _data is a private member of type IData in my DataEditor class. _data gets set in the constructor of my DataEditor to a value that is passed to the constructor. The constructor is called by my DataType class. In my DataType class, the IData object that gets passed to the constructor of my DataEditor is defined as follows:
return _baseData;
When I use this approach, my property always gets assigned null. That is probably because the DefaultData for my DataType is null, which makes sense I suppose. I did check to make sure that when I enter a new value for the property and save the document that the value does get saved to both the DataBase and the umbraco.config file.
I do not understand how the existing value of a property on a specific document that uses my custom DataType is retrieved from the Umbraco database.
is working on a reply...