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.
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:
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.
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 ISupplyValueAndLabelCollectioninterface, 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.
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.
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:
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.
FYI, I created an issue for this here: https://github.com/rhythmagency/formulate/issues/57
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 theIGetValueAndLabelCollection
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:
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.
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).
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
This is great ,thanks !
is working on a reply...