Better Forms Picker #310
-
Hi @leekelleher Would it be possible for you to add a better Forms Picker? The current one only return the GUID of the targeted forms, but will be great to return more data, at least the Name of the form which will help in so may use cases. Unless if I'm missing something that already exists? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
@TRexStark I have made a custom Umbraco Forms data-source for Data List... feel free to use/adapt/modify it... using System;
using System.Collections.Generic;
using System.Linq;
using Umbraco.Community.Contentment.DataEditors;
using Umbraco.Core.PropertyEditors;
using Umbraco.Forms.Core.Services;
using UmbConstants = Umbraco.Core.Constants;
namespace Umbraco.Community.Contentment.Forms
{
public sealed class UmbracoFormsDataSource : IDataListSource, IDataListSourceValueConverter
{
private readonly Lazy<IFormService> _formService;
public UmbracoFormsDataSource(Lazy<IFormService> formService)
{
_formService = formService;
}
public string Name => "Umbraco Forms";
public string Description => "Populate a data source with Umbraco forms.";
public string Icon => UmbConstants.Icons.DataType;
public string Group => nameof(Umbraco);
public OverlaySize OverlaySize => OverlaySize.Small;
public Dictionary<string, object> DefaultValues => default;
public IEnumerable<ConfigurationField> Fields => default;
public IEnumerable<DataListItem> GetItems(Dictionary<string, object> config)
{
return _formService
.Value
.Get()
.Select(x => new DataListItem
{
Name = x.Name,
Value = x.Id.ToString(),
Icon = Icon,
Description = x.GetFormFieldSummary()
});
}
public Type GetValueType(Dictionary<string, object> config) => typeof(Guid);
public object ConvertValue(Type type, string value) => Guid.TryParse(value, out var guid) == true ? guid : Guid.Empty;
}
} I can't include it within the Contentment package itself, as it requires a direct assembly dependency on Umbraco Forms, which I can't make the assumption that every Umbraco site has Umbraco Forms installed. Hope this helps. |
Beta Was this translation helpful? Give feedback.
-
Thanks @leekelleher I understand. And thank you for providing the code. That's very generous of you. |
Beta Was this translation helpful? Give feedback.
@TRexStark I have made a custom Umbraco Forms data-source for Data List... feel free to use/adapt/modify it...