https://github.com/MohdShamweel/JsonToForms
A simple library which uses JSON to build forms : JSON Form Builder
https://github.com/MohdShamweel/JsonToForms
android dynamic-form form-builder forms json-forms
Last synced: about 1 year ago
JSON representation
A simple library which uses JSON to build forms : JSON Form Builder
- Host: GitHub
- URL: https://github.com/MohdShamweel/JsonToForms
- Owner: MohdShamweel
- Created: 2019-11-26T06:19:15.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-01-26T04:14:25.000Z (over 5 years ago)
- Last Synced: 2024-10-31T15:38:29.740Z (over 1 year ago)
- Topics: android, dynamic-form, form-builder, forms, json-forms
- Language: Java
- Homepage:
- Size: 191 KB
- Stars: 6
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- awesome-android - JsonToForms - A simple library which uses JSON to build forms : JSON Form Builder (Uncategorized / Uncategorized)
README
# JsonToForms
A simple library which uses JSON to build forms

## Installation
Step 1. Add the JitPack repository to your build file:
```bash
repositories {
...
maven { url 'https://jitpack.io' }
}
```
Step 2. Add the dependency
```bash
dependencies {
implementation 'com.github.MohdShamweel:JsonToForms:0.1.0'
//Support Material dependency
implementation 'com.google.android.material:material:1.1.0-alpha09'
}
```
Step 3. The dependency contains Java 8 bytecode. Add the following to build.gradle
```bash
android {
compileOptions {
sourceCompatibility 1.8
targetCompatibility 1.8
}
}
```
Step 4. The Activity which contains forms must be a descendant of Material Theme:
```bash
parent="Theme.MaterialComponents.Light.DarkActionBar"
```
Step 5. Sync the Project for gradle to finish.
## Usage
1. Initialize the Hashmap (basically it clears the list):
```bash
DataValueHashMap.init();
```
2. Use the adapter and Object of this library:
```bash
FormAdapter mAdapter;
List jsonModelList = new ArrayList<>();
```
3. Initialize the adapter:
```bash
mAdapter = new FormAdapter(jsonModelList, this, this);
```
4. Implement your Activity to access methods
```
implements JsonToFormClickListener
```
5. Implemented Methods
```bash
@Override
public void onAddAgainButtonClick() {
Toast.makeText(this, "Add Again button click", Toast.LENGTH_SHORT).show();
}
@Override
public void onSubmitButtonClick() {
Toast.makeText(this, "Add Submit button click", Toast.LENGTH_SHORT).show();
}
```
6. To check if fields are validated use the method:
```bash
if (!CheckFieldValidations.isFieldsValidated(recyclerView, jsonModelList)){
Toast.makeText(this, "Validation Failed", Toast.LENGTH_SHORT).show();
}
```
7. To get data:
```bash
//Combined Data:
JSONObject jsonObject = new JSONObject(DataValueHashMap.dataValueHashMap);
Log.d("onSubmitButtonClick: ", jsonObject.toString());
//If single value required for corresponding _id's:
for (Map.Entry hashMap : DataValueHashMap.dataValueHashMap.entrySet()){
String key = hashMap.getKey(); // _id of the JSONOModel provided
String value = hashMap.getValue(); //value entered for the corresponding _id
Log.d(key, value);
}
```
## Fields Types
```
TYPE_TEXT = 1;
TYPE_EDITTEXT = 2;
TYPE_SPINNER = 3;
TYPE_RADIO = 4;
TYPE_DATE = 5;
TYPE_SPACE = 6;
TYPE_CHECKBOX = 7;
TYPE_ADD_AGAIN_BUTTON = 9;
TYPE_SUBMIT_BUTTON = 10;
```
## Sample JSON
```bash
[
{
"_id": "text_1",
"text": "Hi! I'm textview",
"hint": "Hi! I'm textview",
"type": 1
},
{
"_id": "edittext_1",
"text": "Hi! I'm edittext(Enter Numbers)",
"hint": "Hi! I'm edittext(Enter Numbers)",
"input_type": "numbers",
"max_length": 2,
"type": 2
},
{
"_id": "edittext_2",
"text": "Hi! I'm edittext(Enter Numbers Decimal)",
"hint": "Hi! I'm edittext(Enter Numbers Decimal)",
"input_type": "numbers_decimal",
"max_length": 7,
"type": 2
},
{
"_id": "edittext_3",
"text": "Hi! I'm edittext(Enter text) *Required",
"hint": "Hi! I'm edittext(Enter text)",
"input_type": "text",
"is_required": true,
"max_length": 30,
"type": 2
},
{
"_id": "radio_group_1",
"text": "Hi! I'm radio group",
"is_required": true,
"list": [
{
"index": 0,
"index_text": "Radio 1"
},
{
"index": 1,
"index_text": "Radio 2"
},
{
"index": 2,
"index_text": "Radio 3"
},
{
"index": 3,
"index_text": "Radio 4"
}
],
"type": 4
},
{
"_id": "spinner_1",
"text": "Hi! I'm spinner",
"list": [
{
"index": 0,
"index_text": "Item 1"
},
{
"index": 1,
"index_text": "Item 2"
},
{
"index": 2,
"index_text": "Item 3"
},
{
"index": 3,
"index_text": "Item 4"
}
],
"type": 3
},
{
"_id": "again_button",
"text": "Hi! I'm add button",
"type": 9
},
{
"_id": "space_1",
"text": "Hi, I am Space",
"type": 6
},
{
"_id": "submit_button",
"text": "Submit",
"type": 10
}
]
```
## Example:
To know more about implementation please checkout the [Sample App](https://github.com/MohdShamweel/JsonToForms/tree/master/app)
## Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.