ImageFieldDefinition

Posted by Community Admin on 04-Aug-2018 09:02

ImageFieldDefinition

All Replies

Posted by Community Admin on 30-Jul-2013 00:00

Hello,
I have one question. I have some custom content and i want to add image selector to backend definition. ImageFieldElement has done the work: selects image and imageid is saved properly.

But when I want to edit that same item again, image is not loaded in imagefield.
The code for definition is:

var iconImageField = new ImageFieldElement(mainSection.Fields)
    ID = "iconImageFieldControl",
    DataFieldName = "IconImageId",
    DisplayMode = displayMode,
    Title = "IconImage",
    CssClass = "sfFormSeparator",
    WrapperTag = HtmlTextWriterTag.Li,
    ResourceClassId = typeof(ProductsResources).Name,
    DataFieldType = typeof(Guid),
    FieldType = typeof(ImageField)
;
mainSection.Fields.Add(iconImageField);

I think the problem is with DataFieldType=typeof(Guid) . If I use typeof(ContentLink) it would probably worked, but that means I must change many database tables and convert data.
Is there any fast solution?

Posted by Community Admin on 30-Jul-2013 00:00

I found temporary solution:
I extended ImageField control, and change setvalue function in javascript:

public class GuidImageField : ImageField
    
        #region Private Fields and constants
        internal const string script = "GuidImageField.js";
        #endregion
 
        protected override Type ResourcesAssemblyInfo
        
            get
            
                return Config.Get<ControlsConfig>().ResourcesAssemblyInfo;
            
        
         
        public override IEnumerable<System.Web.UI.ScriptReference> GetScriptReferences()
        
            var assemblyName = typeof(GuidImageField).Assembly.FullName;
            var scripts = new List<ScriptReference>(base.GetScriptReferences())
                              
                                  new ScriptReference(GuidImageField.script, assemblyName),
                              ;
            return scripts;
 
        
    


_resolveImageFromGuid: function (itemId)
            var clientManager = new Telerik.Sitefinity.Data.ClientManager();
            var urlParams =
                "itemType": "Telerik.Sitefinity.Libraries.Model.Image",
                "filter": "Id=\"" + itemId + "\" AND Status = Live"
            ;
            if (typeof(this._loadImageSuccessDelegate) === "undefined")
                this._loadImageSuccessDelegate = Function.createDelegate(this, this._loadImageSuccessHandler);
                this._loadImageFailureDelegate = Function.createDelegate(this, this._loadImageFailureHandler);
            
            clientManager.InvokeGet(this._imageServiceUrl, urlParams, null, this._loadImageSuccessDelegate, this._loadImageFailureDelegate, this);
            this._selectedImageItem = null;
            this._imageElement.src = this._defaultSrc;       
    ,
 
    set_value: function (value)        
        if (this._boundOnServer)
            return;
               
                    if (value)
                        this._resolveImageFromGuid(value);
                     else if (!value)
                        this._selectedImageItem = null;
                        this._imageElement.src = this._defaultSrc;
                    
                 
        if (this._imageElement.src == "")
            if (this._defaultSrc)
                this._imageElement.src = this._defaultSrc;
            
        
        this.raisePropertyChanged("value");
        this._valueChangedHandler();       
    

Posted by Community Admin on 02-Aug-2013 00:00

Hi,

The ImageField doesn`t have a way to modify already created image, and to modify a custom solution is needed where to remove the current image. This can be done also with creating a button trough javascript that will remove selected image by placing selected image id to be empty Guid.

Regards,
Stanislav Velikov
Telerik

Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items

This thread is closed