Hi,
one solution could be to add custom validation so that you'll be able to skip the "required" screen, but you will not be able to publish the block until the property has been set. See this forum post: http://world.episerver.com/Modules/Forum/Pages/Thread.aspx?id=123596
Hi Per,
So what you are saying is that i remove the [required] attribute from the block, and create a custom validator (checking if the image is not empty), will cause it to publish the block initially, also creating the "for this block" ?
Yeah, that was what I was thinking. However, I see now that it will not work, as you will not get past the "required" screen anyway. I'm afraid you'll have to find another solution.
I tried it... and it kinda works.. because property 'Image' is not required anymore. So when i create a block, it first tried to publish it, indeed creating the "for this block" folder, and then showing the error from the custom validator. So this is a solution.
Only i have like 10 different kinda block types in my CMS, and all with different kind of 'required' fields. Its quite a hassle making a custom validators for all my block types :-)
How about creating a new attribute to handle the validation. That way you could just put the attribute on your image properties on your blocks:
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false)] public sealed class RequiredImage : ValidationAttribute { public override bool IsValid(object value) { return value != null; } public override string FormatErrorMessage(string name) { return "Add an image, dude!"; } }
and then use it:
[RequiredImage] [UIHint(UIHint.Image)] public virtual ContentReference Image { get; set; }
ahhh.. now we're talking... this would be very elegant. I would just have to create 1 validator for each kinda property type and add the attribute on all the matching props...
thanks Per...
No problem!
You won't need one per property type if you are only going to check for null though. Just rename the attribute to something more generic, and make a generic error message.
is it possible to fetch the property name to add that in the errormessage?
Hi Guys,
for a client I have a question.
Context:
So the client is on a page in the CMS. He can create several type of content blocks. So in a contentarea on the page he clicks on 'create a new block'. There are some required fields like adding an image etc.
The problem:
What the client wants is to before he really creates the block (by clicking create) he wants to have the "for this block" asset folder available, so he can add his required image in that folder and add it to this block.
Now he needs to add a dummy image, create the block for the "for this block" asset folder to appear, and then add his image to the folder and re-add it to the block.
I'm not sure if there is a event i can attach to to create this folder before block creation...
Anyone has any ideas??