This is a migrated thread and some comments may be shown as answers.

Events on RadDataForm: Schema [JSON]

7 Answers 126 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Franchesca
Top achievements
Rank 1
Franchesca asked on 20 Oct 2016, 03:51 PM

 Hello,

I'm wondering if someone can share an example about how to use click events for getting the values of the form that were created using RadDataForm Schema from a json file.

Also if someone can share an example of a json file using properties like 'required' or max and min range will be awesome, you must know that the example that was given on the documentation doesn't work.

Thank you in advance.

 

7 Answers, 1 is accepted

Sort by
0
Todor
Telerik team
answered on 25 Oct 2016, 07:34 AM
Hi Franchesca,

Thank you for contacting us.

When you are editing a json object, you can take the result through dataform's getEditedObject method.

The sample of the schema setup is an excerpt from this example application and should be working. Let us know what issue you observe with it. The schema in the example application contains most of the properties you can setup including min and max range for the stepper editor and min and max range for the range validator.  If the username property for example was required, its definition in the schema would look like this:
{
      "name": "username",
      "editor": "text",
      "required": true
    }

However, if you need to show somehow that a field is required, you will have to do this manually. For example, add a "username *" as a displayName to indicate to the user that the field is required.

Let us know if you need further assistance.

Regards,
Todor
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
0
Franchesca
Top achievements
Rank 1
answered on 25 Oct 2016, 04:38 PM
Thank you for responding.

I didn't fix the issue. I'll be explain you what is happening bellow:

Im trying to use the file named: "person_schema.json" that you provided to me.
{
"isReadOnly": false,

"commitMode": "immediate",

"validationMode": "immediate",

"properties":

[

{

"name": "name",

"displayName": "Your Name"

},

{

"name": "username",

"editor": "text"

},
{

"name": "password",

"editor": "password",

"validator": "MinimumLength",

"validatorParams": {

"length": 5,

"errorMessage": "Password must be at least 5 letters"

}

},

{

"name": "phone",

"editor": "phone"

},

{

"name": "age",

"displayName": "Your Age",

"editor": "stepper",

"editorParams":

{

"minimum": 18,

"maximum": 70

}

},

{

"name": "gender",

"displayName": "Your Gender",

"editor": "picker",

"valuesProvider": ["male", "female"]

},

{

"name": "grade",

"editor": "decimal"

},

{

"name": "email",

"editor": "email",

"validator": "MailValidator",

"displayName": "Your Email"

},

{

"name": "iq",

"editor": "slider",

"validator": "Range",

"validatorParams": {

"min": 60,

"max": 200,

"errorMessage": "IQ can't be less than 60 or more than 200"

}

},

{

"name": "city",

"editor": "segmentededitor",

"valuesProvider": ["New York", "Las Vegas", "Los Angeles"]

},

{

"name": "birthDate",

"editor": "datepicker"

}

]

}


I have no problems when I run something simple like:
{
      "name": "username",
      "editor": "text",
      "required": true
    }

But when I run the person_schema.json I got the following exception:

java.lang.Error: DataFormTextEditor does not support properties of type JSONArray. Please specify a value converter for your property.
                      at com.telerik.widget.dataform.visualization.core.EntityPropertyEditor.load(EntityPropertyEditor.java:157)
                      at com.telerik.widget.dataform.visualization.RadDataForm.load(RadDataForm.java:705)
                      at com.telerik.widget.dataform.visualization.RadDataForm.reload(RadDataForm.java:445)
                      at com.telerik.widget.dataform.visualization.RadDataForm.setEntity(RadDataForm.java:317)
                      at com.telerik.widget.dataform.visualization.RadDataForm.setEntity(RadDataForm.java:276)
                      at cr.co.sea.seaforms.Controller.Fragments.CustomFormFragment.onCreateView(CustomFormFragment.java:56)


Thank you in advance.
0
Todor
Telerik team
answered on 27 Oct 2016, 08:39 AM
Hello Franchesca,

The mentioned example actually uses two json files:person_extended and person_schema. The first one is a representation of one object (a person with its name, age, etc) that will be edited with the data form. The second one is information that will be used by the data form to be property visualized (which editor to be used for editing password, how to validate the input, etc.).

The exception that you reported happens if you use the second file and try to edit is as an object with the data form as you do with the first file.

Here's the usage of the two files in the example:

String json = loadJSONFromAsset(R.raw.person_extended);
 
try {
    JSONObject jsonObject = new JSONObject(json);
    dataForm.setEntity(jsonObject);
 
    String schema = loadJSONFromAsset(R.raw.person_schema);
    JSONObject jsonSchema = new JSONObject(schema);
    DataFormMetadata metadata = new DataFormMetadata(jsonSchema);
    dataForm.setMetadata(metadata);
} catch (JSONException e) {
    Log.e("json", "error parsing json", e);
}

I hope this makes things more clear. If you are still having the issue, you can try to get the application from GitHub, try to run it and let us know if you are having issues wit it.

Regards,
Todor
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
0
Franchesca
Top achievements
Rank 1
answered on 27 Oct 2016, 07:39 PM

Hello Todor,

Hope you´re having an amazing day.

It was very helpful! I really appreciate your answerd. I could understand the example and it worked very good. I just had a problem while trying to test the field for birthday this field must show a datapicker but my apps stops when I try to select that field. The error said:

10-27 13:35:14.605: E/AndroidRuntime(3077): android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
10-27 13:35:14.605: E/AndroidRuntime(3077): at android.view.ViewRootImpl.setView(ViewRootImpl.java:575)
10-27 13:35:14.605: E/AndroidRuntime(3077): at android.view.WindowManagerGlobal.addView(WindowManagerGlobal.java:310)
10-27 13:35:14.605: E/AndroidRuntime(3077): at com.telerik.widget.dataform.visualization.editors.DataFormDateTimeEditor.showDialog(DataFormDateTimeEditor.java:147)
10-27 13:35:14.605: E/AndroidRuntime(3077): at com.telerik.widget.dataform.visualization.editors.DataFormDateTimeEditor.onClick(DataFormDateTimeEditor.java:141)

 

Can you help me out with that error ? 

 

Thank you in advance.

0
Todor
Telerik team
answered on 28 Oct 2016, 01:20 PM
Hi Franchesca,

I am glad you got this to work.

The BadTokenException when using Android Dialogs is a long time issue as you can see from this post from more than 5 years ago. The date picker in RadDataForm is a Dialog which uses the same context that you have passed to the data form's constructor. The solution is to use the activity that contains the form instead of the application context:
RadDataForm dataForm = new RadDataForm(this);

Assuming "this" is an activity. If you are inside a fragment, you can use the getActivity() method to get to the activity and pass it as a context for the data form.

I hope this helps. I wish you a great weekend.

Regards,
Todor
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
0
Franchesca
Top achievements
Rank 1
answered on 14 Nov 2016, 07:57 PM

Awesome! It worked for me. But I think that I have the very last question, how do I change the date format from the schema? It is because it is something like "Fri.,18.11" and I need "dd-mm-yyyy".  

Thank you in advance!

0
Todor
Telerik team
answered on 17 Nov 2016, 09:52 AM
Hi Franchesca,

The format of the date in DataFormDateEditor is not included in the properties supported by the schema. You will need to set the format manually, after the metadata is applied:

dataForm.setMetadata(metadata);
java.text.SimpleDateFormat simpleDateFormat = new java.text.SimpleDateFormat("yyyy-MM-dd", java.util.Locale.US);
((DataFormDateEditor)dataForm.getExistingEditorForProperty("birthDate")).setDateFormat(simpleDateFormat);

This is again taken from the Schema sample, where the birthDate is the property edited with DataFormDateEditor, illustrating where to add the code for the editor date formatting.

I hope this information helps.

Regards,
Todor
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
Tags
DataForm
Asked by
Franchesca
Top achievements
Rank 1
Answers by
Todor
Telerik team
Franchesca
Top achievements
Rank 1
Share this question
or