Editable Attritubes - Conditionally Required + Image Alt

Topics: Developer Forum
Apr 15, 2009 at 3:13 PM
Hey all,

Here is another question I have run into while using N2:

Is it possible to make an editable attribute required based on the value or presence of content in another editable field, here is an example of where this would be used.

                [EditableImage( "Image", 4, ContainerName = Tabs.Content )]
        [FileAttachment]
        public virtual string ImageUrl
        {
            get { return (string)base.GetDetail( "ImageUrl" ); }
            set { base.SetDetail( "ImageUrl", value ); }
        }
Here we have an image which could be displayed on the front end of the site, however accessibility guidelines suggest that every image should have an alt tag (preferably with more than 7 characters and without the word/text image in). In order to make at least the first part of the accessibility guidelines adhered to I added this:

               [EditableTextBox("Image Alt", 5, Required = true)]
        public virtual string ImageAlt
        {
            get { return (string)(GetDetail("ImageAlt") ?? string.Empty); }
            set { SetDetail("ImageAlt", value); }
        }

I want to make it such that the ImageAlt is only required if an image is selected in the field above!

The ultimate goal would be to combine this as part of the [EditableImage] attribute, and allow the other checks:
Min 7 characters
Max 81 characters,
No use of the word image (image, images etc),
No word repeated more than 5 times.
No text .jpg, .gif, .bmp, .jpeg in the alt tag.

If we can solve this it would make a nice addition to N2 :)
Apr 16, 2009 at 10:59 AM
You could used the EditableUserControl and do so using webforms.