Hide semicolon from country selector form control

   —   
In case you use country selector form control e.g. within Document type fields, you might encounter trailing semicolon is added when you don’t choose any USA state.


Actually this behavior is caused by fact that the value is saved to the database in format like: CountryName;StateName. Therefore you see the trailing semicolon. To amend this, you'll need to modify the country selector: ~\CMSFormControls\CountrySelector.ascx.cs. Please find the Value object and change it like this:

get
{
if (this.UseCodeNameForSelection)
{
if (this.StateName != "")
{
return this.CountryName + ";" + this.StateName;
}
else
{
return this.CountryName;
}
}
else
{
return this.CountryID + ";" + this.StateID;
}
}


Also please modify set method:


if (ValidationHelper.GetString(value, "").Contains(";"))
{
string[] ids = ValidationHelper.GetString(value, "").Split(';');

if (ids.Length == 2)
{
if (this.UseCodeNameForSelection)
{
this.CountryName = ValidationHelper.GetString(ids[0], "");
this.StateName = ValidationHelper.GetString(ids[1], "");
}
else
{
this.CountryID = ValidationHelper.GetInteger(ids[0], 0);
this.StateID = ValidationHelper.GetInteger(ids[1], 0);
}
}
}
else
{
if (this.UseCodeNameForSelection)
{
this.CountryName = ValidationHelper.GetString(value, "");
}
else
{
this.CountryID = ValidationHelper.GetInteger(value, 0);
}
}
-ov-


See also: Form controls

Applies to: Kentico CMS 5.0
Share this article on   LinkedIn

Juraj Ondrus

Hi, I am the Technical support leader at Kentico. I'm here to help you use Kentico and get as much as possible out of it.