mattbrailsford / umbraco-fluidity

A fluent CRUD user interface generator for Umbraco
https://our.umbraco.org/projects/backoffice-extensions/fluidity/
Apache License 2.0
48 stars 40 forks source link

Setting data type via name doesn't seem to work when already set via id #72

Closed tcmorris closed 6 years ago

tcmorris commented 6 years ago

Hi Matt,

Came across a bit of an odd one earlier. I wanted to change the data type for DateTime to use the one which includes the time, not just the date. So, I checked what it is called in Umbraco and changed it over to use Umbraco.DateTime on my field config.

Problem was, it was still showing as the default Umbraco.Date data type. Had a quick look through the code and it looks like we have two possible options for setting these values and the defaults are set via an id whereas I was trying to use the name.

If you look here: https://github.com/umco/umbraco-fluidity/blob/da02955af10ffffbee0b0dedbec94de4b6bb287f/src/Fluidity/Configuration/FluidityEditorFieldConfig%60T.cs#L96

and here: https://github.com/umco/umbraco-fluidity/blob/da02955af10ffffbee0b0dedbec94de4b6bb287f/src/Fluidity/Configuration/FluidityEditorFieldConfig%60T.cs#L108

I'm not sure which one of these gets preference? In my case, I had to use the id version to get it working.

mattbrailsford commented 6 years ago

What code did you use to try and change the data type?

tcmorris commented 6 years ago

Like this:

tabConfig.AddField(p => p.DateProperty).SetDefaultValue(() => DateTime.Now).SetDataType("Umbraco.DateTime");

So changing "Umbraco.DateTime" to -36 instead fixed it.

mattbrailsford commented 6 years ago

Yea, the name needs to be the name of the data type instance, not the data type type. So it should be

.SetDataType("Date Picker with time")

tcmorris commented 6 years ago

Ah ok, my bad. Yeah that did the trick. Makes sense now as data type type is indeed something different. Not sure why I missed that, I'll close this one off as all good.

mattbrailsford commented 6 years ago

Understandable mistake, but yea, we need the data type instance as it's that which holds the pre-value config, so if we just used the type, we wouldn't know how it should be configured.