Create 'for this block' assetfolder before creation of a block?

Vote:
 

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??

 

#131300
Jul 20, 2015 15:17
Vote:
 

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

#131302
Jul 20, 2015 15:54
Vote:
 

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" ?

#131303
Jul 20, 2015 16:56
Vote:
 

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.  

#131310
Jul 21, 2015 7:16
Vote:
 

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 :-)

#131312
Jul 21, 2015 8:28
Vote:
 

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; }
#131313
Jul 21, 2015 8:36
Vote:
 

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... 

#131314
Jul 21, 2015 8:41
Vote:
 

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.

#131315
Jul 21, 2015 8:47
Vote:
 

is it possible to fetch the property name to add that in the errormessage?

#131316
Jul 21, 2015 8:49
Vote:
 

The property name should be in the "name" parameter in FormatErrorMessage

#131317
Jul 21, 2015 8:53
Vote:
 

yup... i tried it and you are right.. thanks again.

#131318
Jul 21, 2015 9:07
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.