DataForm dynamic fields

11 posts, 0 answers
  1. roy
    roy avatar
    9 posts
    Member since:
    Mar 2011

    Posted 01 Sep 2016 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
    858 posts

    Posted 05 Sep 2016 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. roy
    roy avatar
    9 posts
    Member since:
    Mar 2011

    Posted 08 Sep 2016 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! ;)

  4. Riaz
    Riaz avatar
    7 posts
    Member since:
    Apr 2017

    Posted 01 Apr in reply to Tsvyatko Link to this post

    Hi Tsvyatko, is this feature available now? Can you please point me to the article mentioned "We will also issue an article describing the specific case of binding the json."

    Thanks in advance

     

  5. Tsvyatko
    Admin
    Tsvyatko avatar
    858 posts

    Posted 06 Apr Link to this post

    Hello Roy,

    Thank you for getting back to us!

    You can check this article how to apply custom datasource to dataform including scenario where JSON is used to supply the data. You can also check the code in our demo app shipped with suite installation - C:\Program Files (x86)\Telerik\UI for Xamarin R1 2017\Examples\XamarinForms 

    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
  6. Riaz
    Riaz avatar
    7 posts
    Member since:
    Apr 2017

    Posted 06 Apr in reply to Tsvyatko Link to this post

    Awesome, thank you Tsvyatko.
  7. Riaz
    Riaz avatar
    7 posts
    Member since:
    Apr 2017

    Posted 26 Oct in reply to Tsvyatko Link to this post

    When building the forms at runtime (where we cannot populate classes with fields upfront) how is the forms GUI field type also dynamically defined? (e.g. DateEditor vs PickerEditor etc). I can see some attributes referring to Type but they appear to be the type of the custom metadata properties of the field, or the type of the field values being committed,  rather than the GUI type of the field itself.  

    Thanks,

  8. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    458 posts

    Posted 27 Oct Link to this post

    Hi Riaz,

    Normally, you're correct and the best practices approach would be to use the type's member to set the editor, for example:

    dataForm.RegisterEditor(nameof(EmployeeModel.Name), EditorType.TextEditor);


    However you can pass a plain string instead:

    dataForm.RegisterEditor(nameof("Name"), EditorType.TextEditor);


    This does require that you need to know what that field's name is going to be. So either you already know what the member names are, or you will need to check the object graph to see what those properties will be first, then set up your editors.

    Regards,
    Lance | Tech Support Engineer, Sr.
    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
  9. Omid
    Omid avatar
    2 posts
    Member since:
    Oct 2017

    Posted 29 Oct in reply to Tsvyatko Link to this post

    Hi
    I used this sample code in this path:
    C:\Program Files (x86)\Telerik\UI for Xamarin R1 2017\Examples\XamarinForms

    Unfortunately, I do not have access to the propertytype atribiute in the initialize method in the CustomMetadataProvider class. I want to create a dynamic dataform with dynamic editor, using a json retrieved from a website. And the dataforms of this program each have different editors  (text, , picker, date, check box…), But since I do not have access to type of editors, I can’t do this. In this Sample, you can only dynamically add a simple texteditor, How can I have a dynamic dataform so that I can dynamically add fields like DateEditor; PickerEditor or CheckBoxEditor?

    Tsvyatko said: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

  10. Lance | Tech Support Engineer, Sr.
    Admin
    Lance | Tech Support Engineer, Sr. avatar
    458 posts

    Posted 30 Oct Link to this post

    Hello Omid,

    The code snippet Tsvyatko provided is a preview of what you'll be able to do an upcoming version of UI for Xamarin. The reason you're not seeing the EntityPropertyMetadata.PropertyType is because it is not available in 2017.3.1018.240 (which is the latest release).

    When it is released, you'll be able to set the property type there and the RadDataForm will provide the appropriate editor for that type. If you have any implementation issues when you first try it, open a support ticket here and we'll dig deeper.


    Note: I noticed that you do not have a license (trial or purchased), make sure you're added as the licensed user so that you can submit tickets. It takes less than a minute to assign you as the user and can be done here on the Manage Licensed Users page.

    Regards,
    Lance | Tech Support Engineer, Sr.
    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
  11. Omid
    Omid avatar
    2 posts
    Member since:
    Oct 2017

    Posted 30 Oct in reply to Lance | Tech Support Engineer, Sr. Link to this post

    Hi Lance

    thanks for the reply. We hope that the next release will be released as soon as possible.

    Thanks for any advice!

Back to Top