Editor 2.4 - Custom Options Function Error (.NET Framework)
Editor 2.4 - Custom Options Function Error (.NET Framework)
It seems something has changed with the Custom Options functionality in Editor 2.4
Previously I had the following code:
editor.Field(new Field("PRODUCT.FlagDuplicate").SetFormatter(Format.NullEmpty()).Options(() => new List<Dictionary<string, object>>
{ new Dictionary<string, object>{{ "value", false}, { "label", "False"} },
new Dictionary<string, object>{{ "value", true}, { "label", "True" } }
}));
This allowed for a "True/False" custom drop down to be filled in the options. The current documentation https://editor.datatables.net/manual/net/options#Custom-function seems to still allow that.
With Editor 2.4 however I am receiving the following error when attempting to compile the code:
Delegate 'Func<Database, string, List<Dictionary<string, object>>>' does not take 0 arguments
Not sure if something got messed up in the build or if this Options custom function has changed in the newest release.
This question has an accepted answers - jump to answer
Answers
As an update, it seems that this method can be replaced by utilizing the new "Add" function on the Options as so:
So I think that part is fine and good to go, except for potentially removing that information from the Manual. However I have slightly more advanced ones that return a List<Dictionary<string,object>> that are a little more complicated, and are throwing the same error.
I've attempted to move them into the Fn() function, but that throws the following:
That's when calling the following:
That function header is:
What's the appropriate return for these situations?
Hi,
The fix is actually really easy - just add two parameters to the function - e.g.:
Becomes:
You don't need to use those new parameters, but due to the strict structure of C# you need to provide them unfortunately. I added those parameters so that there is easy access to the database class, and also the search string (used for
autocomplete
andtags
). As I say, you don't need to use them, but adding them will resolve the compiler error.Sorry for the trouble!
Allan
Thanks as always @allan that was much simpler than I was making it