DataForm dynamic fields

3 posts, 0 answers
  1. roy
    roy avatar
    8 posts
    Member since:
    Mar 2011

    Posted 01 Sep Link to this post

    Hi

    I am trying to create a dynamic dataform with dynamic questions, using a json retrieved from a database.

    These questions can be different types (text, int, picker, date, etc.).

    As far as i understand the only data source you can assign to the dataform is a class of type NotifyPropertyChangedBase. Each property declared in the class is a question in the dataform. 

    How can i dynamically create these properties and set the proper editor based on the type? The json contains the question text and type (among other things but they are not relevant for my problem).

    Thanks for any advice!

    Roy

  2. Tsvyatko
    Admin
    Tsvyatko avatar
    833 posts

    Posted 05 Sep Link to this post

    Hello Roy,

    Currently, our DataForm support only binding to CLR objects. What it currently lack is a suitable extension point to plug the custom generation logic as it currently it requires PropertyInfo properties. However, with the upcoming release (in the mid of Septemeber) we will add an extension point.

    With the updated version you would be able to use the following snippet:

    public class JSONMetadataProvider : PropertyMetadataProviderBase
      {
          private List<EntityProperty> entityProperties = new List<EntityProperty>();
     
          public override List<EntityProperty> EntityProperties
          {
              get
              {
                  return entityProperties;
              }
          }
     
          public override void Initialize(object source)
          {
              var data = JObject.Parse(source.ToString());
     
              foreach (JObject item in data["questions"])
              {
                  foreach (var jProperty in item.Properties())
                  {
                      var metadata = new EntityPropertyMetadata()
                      {
                          Group = ...,
                          Header = ...,
                          PropertyType = ...,
                          PropertyType = ...,
                          ...
                      };
                      var property = new JsonEntityProperty(jProperty, item, metadata);
                  }
              }
          }
      }
     
      public class JsonEntityProperty : EntityProperty
      {
          private JProperty property;
          public JsonEntityProperty(JProperty property, object item, EntityPropertyMetadata metadata) : base(property, item, metadata)
          {
              this.property = property;
          }
     
          public override object OriginalValue
          {
              get
              {
                  return property.Value;
              }
          }
     
          public override void Commit()
          {
              //TODO: implement
              throw new NotImplementedException();
          }
      }


    The setup of the DataForm will look like that:
    dataForm.MetadataProvider = new JSONMetadataProvider();
    dataForm.Source = jsonData;


    We will also issue an article describing the specific case of binding the json.

    Thank you for bringing the use case to our attention. I have updated your telerik points acordingly

    Regards,
    Tsvyatko
    Telerik by Progress
    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
  3. DevCraft banner
  4. roy
    roy avatar
    8 posts
    Member since:
    Mar 2011

    Posted 08 Sep in reply to Tsvyatko Link to this post

    Hey and thanks for the reply

    we have since moved on to using Monotouch.Dialog and are too far in develoment to changing back. But this might come in handy for the next project! ;)

Back to Top