Custom field and events

Topics: Writing modules
May 20, 2011 at 9:15 PM

I'm attempting to write a custom field using the datetime tutorial on the orchardproject.net documentation.  I've basically copied the datetime code and modified it to suit my needs.  Everything seems to be working correctly, and now I want to take it to the next level. 

I've attached my field to a content type, and now I want to run some validation code when the user clicks the save button for that content type.  If it passes validation, proceed, otherwise notify user of failure.

My question is, is it possible to hook into the save event on a content part and run some code to process the textboxes against their validation rules?

May 21, 2011 at 5:55 AM

Presumably your field saves its values in an update method? That's where you can raise model errors.

May 21, 2011 at 2:56 PM

Actually, I don't know where it saves it...I'll have to look back at the docs. I was using this (http://www.orchardproject.net/docs/Creating-a-custom-field-type.ashx), and I don't remember there being a specific update event in there...if that's the case, I can solve it by raising model errors, so I'll look into that, thanks for the suggestion.  I suppose I'd have to use some jquery if I wanted client side validation...

Thanks for your quick response. I'm not new to .NET, but I'm fairly new to MVC and brand new to orchard.  Growing pains for orchard have been present thus far...