Copied to clipboard

Flag this post as spam?

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


  • Jon 8 posts 28 karma points
    Mar 25, 2011 @ 15:21
    Jon
    0

    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.

     

     

     

  • Neil Killen 17 posts 37 karma points
    Mar 25, 2011 @ 17:14
    Neil Killen
    0

    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

  • Jon 8 posts 28 karma points
    Mar 25, 2011 @ 17:39
    Jon
    0

    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.

  • Jon 8 posts 28 karma points
    Mar 28, 2011 @ 14:20
    Jon
    0

    Does anyone have any suggestions?

  • Tom Fulton 2030 posts 4998 karma points c-trib
    Mar 29, 2011 @ 14:57
    Tom Fulton
    0

    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

  • Jon 8 posts 28 karma points
    Mar 29, 2011 @ 15:27
    Jon
    0

    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:

    public override 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.

Please Sign in or register to post replies

Write your reply to:

Draft