How to Create a Dynamic forms App Like ODK Collect

Hello all, I am working on an app that is meant to be used to run surveys like ODK collect and kobotoolbox does. I have already built the web side of things which works very well, also the mobile app is at a phase where the form will be generated. The problem I am having right now is how to create dynamic form based on some defined parameters in JSON or any other source and collect data from the created form. Any help will be duly appreciated.

Answers

  • JuniorJiangJuniorJiang Member, Xamarin Team Xamurai

    Hi @kunleshipo , Here is a forms sample about ODK Collect can refer to.

    If want UI dynamic show data,when using Model data need to use INotifyPropertyChanged .As follow:

    public class HslColorViewModel : INotifyPropertyChanged
    {
        private string name = "520";
        public string Name
        {
            set
            {
                if (name != value)
                {
                    name = value;
                    OnPropertyChanged("Name");
                }
            }
            get
            {
                return name;
            }
        }
        ......
        public event PropertyChangedEventHandler PropertyChanged;
    
        protected virtual void OnPropertyChanged(string propertyName)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }
    }
    

    Here is the official document .

  • kunleshipokunleshipo Member ✭✭

    Thanks a lot for your help @JuniorJiang . I am quite new to xamarin.forms development but I have vast experience with asp.net mvc. I have a class defined with the following properties:

    public class SurveyQuestionDetails
    {
                public int Id { get; set; }
                public int QuestionId { get; set; }
                public int SurveyId { get; set; }
                public int SurveySectionId { get; set; }
                public int SurveySubSectionId { get; set; }
                public string Title { get; set; }
                public string FieldName { get; set; }
                public bool IsRequired { get; set; }
                public int ParentId { get; set; }
                public string ParentType { get; set; }
                public string RelevantCondition { get; set; }
                public string RelevantConditionValue { get; set; }
                public int QuestionTypeId { get; set; } //1 for TextEntry 2 for Select etc.
                public int OptionId { get; set; }
                public int DatasetId { get; set; }
                public bool IsFilterField { get; set; }
                public bool IsReadOnly { get; set; }
                public string DefaultValue { get; set; }
                public int Order { get; set; }
    }
    

    And I am passing a list of questions like this to the content page as follows:

    public List<SurveyQuestionDetails> Questions { get; set; }

    What I need now is how to generate the various controls(Entry, Datepicker, picker etc) to accept input and how to handle such inputs. I have searched and searched and can't seem to get any post that points me in the right direction for this. Any help will be much appreciated.

  • JuniorJiangJuniorJiang Member, Xamarin Team Xamurai

    how to generate the various controls(Entry, Datepicker, picker etc) to accept input and how to handle such inputs.

    Hi @kunleshipo , this need ControlTemplate and Data Templates.According to type of data to show different Controls.

  • kunleshipokunleshipo Member ✭✭

    Thanks @JuniorJiang I will look into that and see how it works

  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭

    I think you have to create with all controls you need, then set their properties according to your model (IsVisible…)

  • kunleshipokunleshipo Member ✭✭
    Thanks @AlessandroCaliaro for your help
Sign In or Register to comment.