Code Monkey home page Code Monkey logo

formmaster's Introduction

Form-Master

Download

Easily build big and bigger forms with minimal effort

This library aids in building bigger forms on-the-fly. Forms with large number of elements can easily be added programmatically within a few minutes.

Features

  • Easily build big and bigger forms with minimal effort
  • Fast color change as needed

Installation

Add this in your app's build.gradle file:

compile 'me.riddhimanadib.form-master:form-master:1.1.0'

How to use

  1. Add a Recyclerview anywhere in the layout where you want your list to be shown (If confused, look at the examples in this repo).
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <android.support.v7.widget.RecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:id="@+id/recyclerView"
        android:descendantFocusability="beforeDescendants" />

</LinearLayout>
  1. Add the Form Elements programmatically in your activity
// initialize variables
mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView);
mFormBuilder = new FormBuildHelper(this, mRecyclerView);

// declare form elements
FormHeader header = FormHeader.createInstance("Personal Info");
FormElementTextEmail element = FormElementTextEmail.createInstance().setTitle("Email").setHint("Enter Email");
        
// add them in a list
List<FormObject> formItems = new ArrayList<>();
formItems.add(header);
formItems.add(element);

// build and display the form
mFormBuilder.addFormElements(formItems);
mFormBuilder.refreshView();
  1. Now build and run!!

Changelog

####v1.1.0

  1. New FormElement type: Switch.
  2. New way to define the form elements.
  3. Can set Titles in alert dialogs for Date and Time type form element.
  4. Can set Positive and negative texts for Date, Time and Switch type form elements.
  5. Can set Date and Time formats (if unset, default format will be used).

Reference

Item Definition

Header:

FormHeader header = FormHeader.createInstance("Personal Info");

Regular Elements:

General object format

<Class> element = <Class>.createInstance()
    .setTag(101123151) // optional tag to uniquely identify the elemnt for later use
    .setType(FormElement.TYPE_PICKER_MULTI_CHECKBOX) // setting input type
    .setTitle("Pick your favourite fruit") // setting title
    .setValue("Banana") // setting value of the field, if any
    .setOptions(fruits) // setting pickable options, if any
    .setHint("e.g. banana, guava etc") // setting hints, if any
    .setRequired(false); // marking if the form element is required to be filled to make the form valid, include if needed

Samples:

// email input
FormElementTextEmail element = FormElementTextEmail.createInstance().setTitle("Email").setHint("Enter Email");

// phone number input
FormElementTextPhone element = FormElementTextPhone.createInstance().setTitle("Phone").setValue("+8801712345678");

// single line text input
FormElementTextSingleLine element = FormElementTextSingleLine.createInstance().setTitle("Location").setValue("Dhaka");

// multi line text input (default 4)
FormElementTextMultiLine element = FormElementTextMultiLine.createInstance().setTitle("Address");

// number element input
FormElementTextNumber element = FormElementTextNumber.createInstance().setTitle("Zip Code").setValue("1000");

// date picker input
FormElementPickerDate element = FormElementPickerDate.createInstance().setTitle("Date").setDateFormat("MMM dd, yyyy");

// time picker input
FormElementPickerTime element = FormElementPickerTime.createInstance().setTitle("Time").setTimeFormat("KK hh");

// password input
FormElementTextPassword element = FormElementTextPassword.createInstance().setTitle("Password").setValue("abcd1234");

// switch input
FormElementSwitch element = FormElementSwitch.createInstance().setTitle("Frozen?").setSwitchTexts("Yes", "No");

// single item picker input
List<String> fruits = new ArrayList<>();
fruits.add("Banana");
fruits.add("Orange");
fruits.add("Mango");
fruits.add("Guava");
FormElementPickerSingle element = FormElementPickerSingle.createInstance().setTitle("Single Item").setOptions(fruits).setPickerTitle("Pick any item");

// multiple items picker input
List<String> fruits = new ArrayList<>();
fruits.add("Banana");
fruits.add("Orange");
fruits.add("Mango");
fruits.add("Guava");
FormElementPickerMulti element = FormElementPickerMulti.createInstance().setTitle("Multi Items").setOptions(fruits).setPickerTitle("Pick one or more").setNegativeText("reset");

Set form element value change listener to get changed value instantly

While creating new instance of FormBuildHelper, add a listener in the constructor

Have a look at the example code for details

FormBuildHelper mFormBuilder = new FormBuildHelper(this, mRecyclerView, new OnFormElementValueChangedListener() {
    @Override
    public void onValueChanged(FormElement formElement) {
        // do anything here with formElement.getValue()
    }
}
);

Set unique tags for form elements (for later value retrieval)

Just add a unique tag for the element

FormElement element = FormElement.createInstance()
    .setTag(2149) // unique tag number to identify this element
    .setType(FormElement.TYPE_PICKER_MULTI_CHECKBOX)
    .setTitle("Pick your favourite fruit");

Get value for unique form elements

Use the unique tag assigned earlier to retrieve value (See examples in this repo)

FormElement targetElement = mFormBuilder.getFormElement(2149);
String targetValue = targetElement.getValue();

Check if form is valid

Use this method if you need to check whether the required elements of the form is completed

mFormBuilder.isValidForm(); // returns boolean whether the form is valid or not

Form accent color change

If you want to change the colors, just override the colors in your colors.xml file:

<color name="colorFormMasterHeaderBackground">#DDDDDD</color>
<color name="colorFormMasterHeaderText">#000000</color>
<color name="colorFormMasterElementBackground">#FFFFFF</color>
<color name="colorFormMasterElementTextTitle">#222222</color>
<color name="colorFormMasterElementTextValue">#000000</color>
<color name="colorFormMasterDivider">#DDDDDD</color>

Form UI change

If you want to change how the forms look, just override the layout xml named form_element.xml and/or form_element_header.xml in your project.

Just make sure to keep the ID name same as it is in the library for the components.

android:id="@+id/formElementTitle"
android:id="@+id/formElementValue"

Contributing

Send Pull Requests and you're in!! Alternatively, you can start adding issues here in this repo!

License

This Library is released under the Apache License, Version 2.0.

formmaster's People

Contributors

adib2149 avatar mihirsane avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

formmaster's Issues

Custom Fields

I wanted to add a field of name is it possible to add? Or any other custom field which is not present in the Types?

监听问题

如果head是页数
我需要判断当前滑动到多少页该怎么处理呢

现在的每一条数据都是一个position

Can we check data at realtime !

For example : FormElement.TYPE_SPINNER_DROPDOWN

When i choose item from FormElement.TYPE_SPINNER_DROPDOWN => i wanna add new FormElement to formItems or remove FormElement from formItems ! [suck like checkbox or selection in d forms at website]

Can i do that !

Password type

I downloaded the example and run it but I can see the password. I want to see as stars (*****).
How can I do it?

switch

It is possible to add switch control to next version? It is really missing here.

Default value get empty after form submit

@adib2149 i am using your lib long ago, now i have upgraded to latest one but there is road block issue i am facing. please check it. Thanks in advance.

  1. For Number field (first field in whole form) once we set default value and in submit action if you try to get value of that element then it is getting empty.
  2. But for same number field if you edit it to another value then it gives right value.

File picker

Is there any chance to include a file picker form element?!?!?

"FormHeader" checked when "isValidForm" method is executed

First of all, well done for this tool.
My concern: "isValidForm" method fetches all FormElement to check if they have value as they are required.
However, while fetching, "isValidForm" method takes "FormHeader" which is not a FormElement. Consequently, there is an exception thrown:
excep
Thanks for your attention.

Switch issue

Hi,

I was wondering if anyone has reported an issue with the switches when using this library. Scrolling down the list and clicking the switches seems to change a switch that is located somewhere else in the list rather than the position I have selected.

I can provide some code if you need. I've followed all the examples and everything seems to be working fine apart from this Switch issue.

Number format

Hi, Can change to use a decimal number format too

Dynamically hide element?

Is there a way to hide an element once it's created? I want to use a change listener to show/hide available fields.

Unable to add library

Unable to add this library; getting error when I add this library:

\app\build\intermediates\res\merged\debug\values-v24\values-v24.xml
Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
Error:(4) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.
Error:(3) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Borderless.Colored'.
Error:(4) Error retrieving parent for item: No resource found that matches the given name 'android:TextAppearance.Material.Widget.Button.Colored'.

Time issue

hi,
the time picker doesn't work there an issue with the minute picker always show 05 in the form

Custom validation

how to add custom validation to fields?????
like regex or something

isValidForm always return true

Hi! First thanks for this project, is very very usefull.

I have a question, why isValidFrom method from FormBuildHelper always return true?

Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.