Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Customizing Bizform field and overall validation error message display View modes: 
User avatar
Member
Member
matt-awg - 9/19/2013 2:33:24 PM
   
Customizing Bizform field and overall validation error message display
I am creating a custom bizform. I have it all working except for two issues I am having with trying to better control the output of the error messages when field validation errors occur. I do NOT need to know how to customize the individual messages themselves, that is simple enough. What I want is to customize the placement of them.

1) The overall message that is being displayed when the form fails some validation. I just want to totally hide this message.

2) The individual validation messages per field. I want to combine all of these messages inside one DIV that only appears on the form when an error occurred.

for item 1) I tried overriding the ValidationErrorMessage property in the custom bizform control and set it return empty string and also tried adding this to the SetupControl function:
viewBiz.ValidationErrorMessage = "";

but no matter what it still displays a general validation error message on the submission of a form missing fields.

for item 2) I first tried just doing this in CMSDesk with a custom form, which allows me to stick the validation labels all at the top of the page but they are each in their own SPAN that Kentico generates and I can't just wrap them in a DIV here because the error div will always appear. (so my red div with exclamation icon appears even when no validation error is present). I was playing with outputting some custom JS to hide the div maybe but that just seems like hack.

Then I tried overriding the bizForm onPreRender and attempted to access the viewBiz.BasicForm.FieldErrorLabels collection. The idea was to loop through them, and combine them all into one custom div that I could output when one or more of them had a value. Unfortunately, I can't figure out how to access these objects. Does anyone know what type this collection is? I have tried 20 different ways of loop through this, casting it to many different things and I can't get it to work. I consulted the API documentation and it literally has NO information on this:

Kentico CMS 7.0 API Reference
FieldErrorLabels Property

Namespaces ► CMS.FormControls ► BasicForm ► FieldErrorLabels
Copyright (c) 2012 Kentico Software

Assembly: CMS.FormControls (Module: CMS.FormControls) Version: 7.0.4639.32326


Really helpful stuff...

I was able to get this loop to work:
for (i = 0; i < viewBiz.BasicForm.FieldErrorLabels.Count; i++)


But I can't cast viewBiz.BasicForm.FieldErrorLabels\[i\] to anything that does not throw an error. I tried CMS.FormControls.FormErrorLabel, and CMS.ExtendedControls.LocalizedLabel, and some other things...

I found this documentation:
http://devnet.kentico.com/docs/devguide/index.html?api_bizforms_customization_possibilities.htm

it mentions hash tables
If you wish to set up special behavior in the form during the editing process, individual controls that make up the fields, labels and validation error messages in the form can be accessed through the hash tables provided by the BizForm.BasicForm.FieldControls, BizForm.BasicForm.FieldLabels and BizForm.BasicForm.FieldErrorLabels properties.

but I tried casting to several types of collections with no luck.

Anyone have any idea how to achieve these two things?
THANKS!
Matt

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 9/20/2013 7:52:30 AM
   
RE:Customizing Bizform field and overall validation error message display
To totally hide the form error message I believe you can set this in the PreRender event
bizForm.ValidationErrorMessage = "";]/code]Kentico doesn't wrap a < span > around the error message, that's standard asp.net validation control html.

My suggestion for 2 was the same as you tried but totally forgot about it always displaying. Some jQuery might be the best bet.

In regards to viewBiz.BasicForm.FieldErrorLabels collection. If you hover over the FieldErrorLabels property in Visual Studio it simply states
CMS.SettingsProvider.StringSafeDictionary<CMS.ExtendedControls.LocalizedLabel>
So it looks like an IDictionary of localized label controls.

Hope that helps.

User avatar
Member
Member
matt-awg - 9/20/2013 10:04:46 AM
   
RE:Customizing Bizform field and overall validation error message display
Hi FroggEye,

Thanks for the help... you pointed me enough in the right direction that I was able to get item 2) working... I added a literal control on the custom form called ltrErrorMessages and the code below works in building one div with all the error messages! But the overall validation error message still is showing up... I don't get it.
I tried adding bizForm.ValidationErrorMessage = ""; all over the place in every event I could think of... no luck. I will just see if I can hide it via CSS or JQUERY. Here is the code in case anyone else wants to do something similar:

        string errMsg = "";

foreach (System.Collections.DictionaryEntry dict in viewBiz.BasicForm.FieldErrorLabels)
{
CMS.ExtendedControls.LocalizedLabel ctrl = (CMS.ExtendedControls.LocalizedLabel)dict.Value;
if (ctrl != null)
{
if (!ctrl.Text.Equals(""))
{
errMsg += "<span class=\"missingFieldMessage\">" + ctrl.Text + "</span>";
ctrl.Visible = false;
}
}
}

if (!errMsg.Equals(""))
{
ltrErrorMessages.Visible = true;
ltrErrorMessages.Text = "<div class=\"error\">" + errMsg + "</div>";
}
else
{
ltrErrorMessages.Visible = false;
}


Thanks again,
Matt