DataForm with enum filed throws exception on Android.

3 posts, 0 answers
  1. John
    John avatar
    2 posts
    Member since:
    Dec 2016

    Posted 12 Jul Link to this post

    I need to have a language select drop down on a data form so I used a language enum as one of the properties on the view model. The drop-down works fine on UWP but throws an exception when rendering on Android. It works fine on Android if I change the field type to string instead of enum. Here is the view model:

    public class AppConfiguration
        {
        [DisplayOptions(Header = "API URL")]
        public string ApiUrl { get; set; }
     
        [DisplayOptions(Header = "Preferred Culture")]
        [Ignore]
        public string Culture { get; set; }
     
        public enum LanguageChoices { English, French };
     
        //[DisplayOptions(Header = "Preferred Language")]
        //public string LanguageChoice
        //  {
        //  get
        //      {
        //      if(string.IsNullOrEmpty(Culture))
        //          Culture="en-CA";
        //      switch(Culture.Substring(0, 2).ToLower())
        //          {
        //      case "en":
        //          return "English";
        //      case "fr":
        //          return "French";
        //      default:
        //          return "English";
        //          }
        //      }
        //  set
        //      {
        //      switch(value.Substring(0, 2).ToLower())
        //          {
        //      case "fr":
        //          Culture="fr-CA";
        //          break;
        //      case "en":
        //          Culture="en-CA";
        //          break;
        //      default:
        //          Culture="en-CA";
        //          break;
        //          }
        //      }
        //  }
     
        [DisplayOptions(Header = "Preferred Language")]
        public LanguageChoices LanguageChoice
            {
            get
                {
                if(string.IsNullOrEmpty(Culture))
                    Culture="en-CA";
                switch(Culture.Substring(0, 2).ToLower())
                    {
                case "en":
                    return LanguageChoices.English;
                case "fr":
                    return LanguageChoices.French;
                default:
                    return LanguageChoices.English;
                    }
                }
            set
                {
                switch(value)
                    {
                case LanguageChoices.French:
                    Culture="fr-CA";
                    break;
                case LanguageChoices.English:
                    Culture="en-CA";
                    break;
                default:
                    Culture="en-CA";
                    break;
                    }
                }
            }
        }
  2. John
    John avatar
    2 posts
    Member since:
    Dec 2016

    Posted 13 Jul in reply to John Link to this post

    Just to make sure that there was nothing else in my program aggravating the issue, I was able to reproduce the problem in the Telerik SDKBrowswer sample simply by adding the following lines to SourceItem.cs in the DataForms sample:

    public enum LanguageChoices { English, French };
     
    [DisplayOptions(Header = "Language")]
    public LanguageChoices Language { get; set; }
  3. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    501 posts

    Posted 17 Jul Link to this post

    Hello John,

    As my colleague has advised in the ticket you have raised - enumerations are not supported by the default editors. With this in mind, you can use a PickerEditor or a SegmentedEditor in order to edit such properties. Please have a look at the "Editors" example in our SDK Samples Browser where a Segmented editor is used for the "TargetGroup" property of the book object.

    Regards,
    Stefan Nenchev
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top