You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
i try to create a new widget for showing up countries in a dropdownlist on a form.
sofar the control is initializing and showing up some data.
but - if i try to change the properties on it - for example "required" or "label/question" - it does not keep the values and does not give it back to the designer either.
/// <inheritDocs />
public string SerializedChoices
{
get
{
if (string.IsNullOrEmpty(this.serializedChoices))
{
this.serializedChoices = this.BuildInitialChoicesString();
}
return this.serializedChoices;
}
set
{
this.serializedChoices = value;
}
}
/// <inheritDocs />
[TypeConverter(typeof(ExpandableObjectConverter))]
public override ValidatorDefinition ValidatorDefinition
{
get
{
if (this.validatorDefinition == null)
{
this.validatorDefinition = base.ValidatorDefinition;
this.validatorDefinition.RequiredViolationMessage = Res.Get<FormResources>().RequiredInputErrorMessage;
}
return this.validatorDefinition;
}
set
{
this.validatorDefinition = value;
}
}
/// <inheritDocs />
public override IMetaField GetMetaField(IFormFieldControl formFieldControl)
{
var metaField = base.GetMetaField(formFieldControl);
if (string.IsNullOrEmpty(metaField.Title))
{
metaField.Title = Res.Get<FieldResources>().SelectChoice;
}
if (string.IsNullOrEmpty(metaField.DefaultValue))
{
var choices = this.DeserializeChoices();
if (choices.Any())
{
metaField.DefaultValue = choices.FirstOrDefault();
}
}
return metaField;
}
/// <summary>
/// Prepopulates the initial choices.
/// </summary>
/// <returns></returns>
public virtual string BuildInitialChoicesString()
{
var initialChoices = new string[]
{
Res.Get<FieldResources>().OptionSelect,
Res.Get<FieldResources>().OptionFirstChoice,
Res.Get<FieldResources>().OptionSecondChoice
};
return JsonConvert.SerializeObject(initialChoices);
//var cultureList = LocationContext.Instance.Cultures("en");
//var orderedcultureList = cultureList.OrderBy(x => x.CountryName).ToList();
//return JsonConvert.SerializeObject(orderedcultureList.Select(x => x.CountryName).ToArray());
}
/// <inheritDocs />
public override bool IsValid(object value)
{
if (this.ValidatorDefinition.Required.HasValue && this.ValidatorDefinition.Required.Value)
{
var strValue = value as string;
if (!string.IsNullOrEmpty(strValue))
{
var choices = this.DeserializeChoices();
if (choices.Contains(strValue))
{
return base.IsValid(value);
}
}
return false;
}
else
{
return base.IsValid(value);
}
}
public IEnumerable<string> DeserializeChoices()
{
if (string.IsNullOrEmpty(this.SerializedChoices))
{
return Enumerable.Empty<string>();
}
return JsonConvert.DeserializeObject<IEnumerable<string>>(this.SerializedChoices);
}
/// <inheritDocs />
private string BuildValidationAttributesString()
{
if (this.ValidatorDefinition.Required.HasValue && this.ValidatorDefinition.Required.Value)
{
return "required='required'";
}
return string.Empty;
}
public override object GetViewModel(object value, IMetaField metaField)
{
//workaround
var cultureList = LocationContext.Instance.Cultures("en");
var orderedcultureList = cultureList.OrderBy(x => x.CountryName).ToList();
var countrySelectList = DataObjectConverter<List<SelectListItem>>.ConvertToViewModel(cultureList);
List<string> countrStrings = new List<string>();
foreach (var item in orderedcultureList)
{
countrStrings.Add(item.CountryName);
}
this.Value = value;
return new CountryViewModel()
{
Value = value,
CssClass = this.CssClass,
MetaField = metaField,
IsRequired = this.ValidatorDefinition.Required.HasValue ? this.ValidatorDefinition.Required.Value : false,
ValidationAttributes = this.BuildValidationAttributesString(),
RequiredViolationMessage = this.ValidatorDefinition.RequiredViolationMessage,
Countries = countrySelectList,
Choices = countrStrings
};
}
The text was updated successfully, but these errors were encountered:
mbarmettler
changed the title
Dropdownlist Read.defaul.cshtml missing Model.MetaField
custom Dropdownlist does not keep attributes / properties
Jan 16, 2019
Hi,
i try to create a new widget for showing up countries in a dropdownlist on a form.
sofar the control is initializing and showing up some data.
but - if i try to change the properties on it - for example "required" or "label/question" - it does not keep the values and does not give it back to the designer either.
here is my controller:
``
private ValidatorDefinition validatorDefinition;
private string serializedChoices;
The text was updated successfully, but these errors were encountered: