Copied to clipboard

Flag this post as spam?

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


  • Max 6 posts 76 karma points
    Aug 26, 2016 @ 07:55
    Max
    0

    Customize Data Value Section

    Hi ,

    Anyone has done some customization on Data Value section? Says if I want to add some additional textbox (eg. 'Json Url field') ?

    This is due to I want to set the datasource through store proc/ web api instead of set the Items in backoffice.

    Currently I found that it seem like the only way is to change the formulate.js file and I am not sure whether this is the right way to doing this. Appreciate if anyone may advice.

    enter image description here

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Aug 26, 2016 @ 15:36
    Nicholas Westby
    0

    In theory (though, apparently not yet in practice, which I'll get to below), all you should need to do is implement IDataValueKind and create the Angular directive in the back office, as demonstrated by the data value list:

    The problem is this block of code in DropDownField.cs:

    var strItems = kind is DataValueList ? ExtractList(dataValue.Data) : new List<string>();
    items.AddRange(strItems.Select(x => new DropDownItem()
    {
        Label = x,
        Selected = false,
        Value = x
    }));
    

    Notice that it's checking specifically if the picked data value kind is a DataValueList, and if it isn't it's just using an empty list.

    In order for you to do what you are trying to do, I'll need to modify Formulate so that any data value kind can be used with the drop down. I'll try to get to that this weekend.

    If this is super urgent, you could get around this by creating a custom field type that is based on the existing drop down field type, but that knows about your new data value kind.

    By the way, just to be clear, are you planning to use this to populate a drop down? Also, is it OK if the values and the labels for the drop down items are the same, or do you need them to be different? That'll help me decide on what to focus on when I make the necessary changes.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Aug 26, 2016 @ 15:49
    Nicholas Westby
    0

    FYI, I created an issue for this here: https://github.com/rhythmagency/formulate/issues/57

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Aug 28, 2016 @ 03:31
    Nicholas Westby
    0

    FYI, this has been implemented. New data value kinds should now work with the drop down, so long as they implement either the IGetStringCollection or the IGetValueAndLabelCollection interface.

    In your case, however, that probably won't be necessary, as the new data value kind I added ("List Function") allows you to create a function that returns a list of data to be shown in a drop down. If you use this data value kind, all you need to do is implement the ISupplyValueAndLabelCollection interface, which you can see an example of in UsStateSupplier.cs.

    Here's a very simple example of what you'd have to do:

    public class SomeDataSupplier : ISupplyValueAndLabelCollection
    {
        public string Name { get; } = "I Supply Two Items of Data";
        public IEnumerable<ValueAndLabel> GetValues()
        {
            return new List<ValueAndLabel>()
            {
                new ValueAndLabel()
                {
                    Value = "1",
                    Label = "Item 1"
                },
                new ValueAndLabel()
                {
                    Value = "2",
                    Label = "Item 2"
                }
            };
        }
    }
    

    And that's it. Formulate will use some reflection to find your class so that your values can be used as the data values in a drop down.

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Aug 28, 2016 @ 03:32
    Nicholas Westby
    0

    Oh, I forgot to mention. This change hasn't been released yet as a new Formulate version. That should happen shortly (within a couple days).

  • Nicholas Westby 2054 posts 7103 karma points c-trib
    Aug 29, 2016 @ 15:53
    Nicholas Westby
    1

    The above data value changes can be found in the latest version of Formulate. You can read about it here: https://our.umbraco.org/projects/backoffice-extensions/formulate/formulate-questions/79633-formulate-036-just-released-data-value-list-functions

  • Max 6 posts 76 karma points
    Sep 19, 2016 @ 02:17
    Max
    0

    This is great ,thanks !

Please Sign in or register to post replies

Write your reply to:

Draft