umbraco-multi-url-picker icon indicating copy to clipboard operation
umbraco-multi-url-picker copied to clipboard

Using Multi Url Picker without Models builder

Open jattwood opened this issue 6 years ago • 3 comments

Trying to use Multi Url Picker without models builder. Strongly typed, not dynamic. It would be great to include an example of this on the readme page similar to the below. I am assuming that I can test for data with HasValue() per below?

if (searchItem.HasValue("overviewLinks"))
                    {
                        var multiUrlPicker = searchItem.GetPropertyValue<IEnumerable<Link>>("overviewLinks");
                        
                        if (multiUrlPicker.Any() && multiUrlPicker != null)
                        {
                            <ul>
                                @foreach (var item in multiUrlPicker)
                                {
                                    <li><a href="@item.Url" target="@item.Target">@item.Name</a></li>
                                }
                            </ul>
                        }
                    }

jattwood avatar Jan 17 '19 19:01 jattwood

Having a quick look at the source I'm not entirely sure that .HasValue() always works, but .GetValue<IEnumerable<Link>>() should always return a collection (if using v1 or if using v2 and the Max number of items pre value is greater than 1) where you can use multiUrlPicker.Any()

If Max number of items is 1 and you are using v2+ you can use .GetPropertyValue<Link>() and do a null check afterwards

rasmusjp avatar Jan 17 '19 19:01 rasmusjp

Thanks for your quick response. on 7.12.3 looks like HasValue() is working as far as I can tell. Since most property editors offer this as a universal value presence test, it would be great to ensure that that is in there. This picker is sorely missing in the core of Umbraco and desperately needed. Thanks for making this available!

jattwood avatar Jan 18 '19 19:01 jattwood

Nice to know it's working. I'm happy to let you know it's going to be a part Umbraco 7.14 (https://github.com/umbraco/Umbraco-CMS/commit/e1c9b1818ee639bf2136d06654121299d6473d49).

rasmusjp avatar Jan 21 '19 19:01 rasmusjp