This project is read-only.

Content editor and required parts

Topics: Writing modules
Jun 5, 2013 at 2:15 PM
I have a custom content type, build in C# code. It has a content item, which the user chooses with the content picker. There is also a document, that is selected from the media library. All works fine, except I need the user to select EITHER a content item or a document. I can set those individually to required or not, but how do I code in the requirement of having exactly one of those? If it's too hard to do in C# maybe there's a way to inject a small amount of validation Javascript? It's an internal site, so security is not very important.
Jun 8, 2013 at 12:13 AM
Not sure what the difficulty is here. What did you try and how did it fail?
Jun 10, 2013 at 2:38 PM
So I have a custom content type. It has two important parts:
  1. A document, with a single field of type MediaPickerField.
  2. A content, with a single field of type ContentPickerField.
I can set either of them to required or not, but what I need is to enforce that exactly one of those two is set.
Jun 10, 2013 at 3:31 PM
Edited Jun 10, 2013 at 6:13 PM
I would try by creating a new content part to manage them. Adding these two fields to the content part instead of the content type for clarity. I would also chuck them in with a migration too so the module can keep track of the field names better.

During the driver update you can then navigate the fields of the part I expect (hopefully the fields have been set after the updater.TryUpdateModel line I may be wrong) and determine yourself if the fields are valid and return a modal error through IUpdater. Ive not done it quite this way before as I normally check for things and react during content handler phases, but I cant think of a way to cancel the save and returning a modal error from there.

Any other way would be good to know too ;-)
Jun 19, 2013 at 11:00 AM
Thanks Matt.