November Happy Hour will be moved to Thursday December 5th.

Episerver Autofill forms for Readonly textbox not working

Vote:
 

Hi,

When trying to implement Autofill functionality for my Readonly textbox it throws an exception in line 'Model.GetDefaultValue'. Can someone please help me in getting this fixed and let me know if we can use Episerver Autofill feature for Readonly Textbox. Below are the details of my code:

My AutoFill class looks like below:

public string Id
        {
            get 
			{ 
				return "DLAutofillSystem"; 
			}
        }

        public IEnumerable<IDatasource> Datasources
        {
            get
            {
                Datasource dataSource = new Datasource()
                {
                    Id = "DLDataSource",
                    Name = "DL Data Source",
                    OwnerSystem = this,
                    Columns = new Dictionary<string, string> 
					{
                        { "DLName", "DL Name" }
                    }
                };

                return new[] { dataSource };
            }
        }

        public IEnumerable<string> GetSuggestedValues(IDatasource selectedDatasource, IEnumerable<RemoteFieldInfo> remoteFieldInfos, ElementBlockBase content, IFormContainerBlock formContainerBlock, HttpContextBase context)
        {
            if (selectedDatasource == null || remoteFieldInfos == null)
            {
                return Enumerable.Empty<string>();
            }

            if (!this.Datasources.Any(ds => ds.Id == selectedDatasource.Id) // datasource belong to this system
               || !remoteFieldInfos.Any(mi => mi.DatasourceId == selectedDatasource.Id)) // and remoteFieldInfos is for our system datasource
            {
                return Enumerable.Empty<string>();
            }

            RemoteFieldInfo activeRemoteFieldInfo = remoteFieldInfos.FirstOrDefault(mi => mi.DatasourceId == selectedDatasource.Id);

            switch (activeRemoteFieldInfo.ColumnId)
            {
                case "DLName":

                    if (context.Request.QueryString["id"] != null)
                    {
                        if (int.TryParse(context.Request.QueryString["id"], out int DLId))
                        {
                            return new List<string> { GetDLName(DLId) };
                        }
					}

                    return Enumerable.Empty<string>();

                default:
                    return Enumerable.Empty<string>();
            }
        }

Error details:

Getting the error after selecting the datasource for the FormElement. It works normally without the datasource.

Thank you.

#256994
Jun 23, 2021 13:37
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.