Custom Field Tutorial

Topics: Troubleshooting
Jul 21, 2015 at 4:55 PM
So I tried the tutorial here to create the custom date time field in Orchard 1.9.1 and I'm getting errors when I try to use it.

First up, if I try to add the field to a content type, call it 'Test' I get an error "The model item passed into the dictionary is of type 'CustomFields.DateTimeField.Settings.DateTimeFieldSettings', but this dictionary requires a model item of type 'Orchard.Fields.Settings.DateTimeFieldSettings'. " when I try to add the field to a type, and secondly, If I try to create new 'Test' I also get an error "A 'stylesheet' named 'jQueryUI_DatePicker' could not be found. "

I do have jQuery enabled, and all the other things in suggested in the tutorial, I even tried downloading the source code from the tutorial and using that in case of typos, but it gives the same error. It doesn't matter what theme I use, I've tried several, in the hope that one of them may have the jQuery files installed, but to no avail so far.
Developer
Jul 21, 2015 at 10:24 PM
Edited Jul 21, 2015 at 10:24 PM
Could you have imported the wrong namespace in your custom field view? Notice the difference between 'CustomFields...' and 'Orchard...'
Jul 22, 2015 at 7:55 AM
Edited Jul 22, 2015 at 8:03 AM
As sfmskywalker suggested you probably have this in top of your view:
@model Orchard.Fields.Settings.DateTimeFieldSettings
Just replace it with your own settings model:
@model CustomFields.DateTimeField.Settings.DateTimeFieldSettings
Regarding the jQueryUI error, as you can see it can't find the stylesheet jQueryUI_DatePicker. That is because there is no such a stylesheet, I think you meant to require the script. You probably have this in your view:
Style.Require("jQueryUI_DatePicker");
This should be:
Script.Require("jQueryUI_DatePicker");
EDIT

Looking at the tutorial, I think it isn't updated for Orchard 1.9 and above. Take a look at the ResourceManifest.cs from the Orchard.jQuery module to see which scripts and stylesheets are available. There isn't a stylesheet 'jQueryUI_DatePicker' anymore.