Giter Club home page Giter Club logo

simple-form's Introduction

simple-form

Add this in your project's build.gradle (project level)
	allprojects {
		repositories {
			...
			maven { url 'https://jitpack.io' }
		}
	}
Add this in your project's build.gradle (app level)
	dependencies {
	        implementation 'com.github.lspradeep:simple-form:v1.0.1'
	}

Table of content

1. How to create a simple form

2. How to create a sectioned form

3. How to create a sectioned form and show only one section at a time




1. How to create a simple form

Alt Text Alt Text

Step 1:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.pradeep.form.simple_form.SimpleFormView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

Step 2: (just describe your form item)

import com.pradeep.form.simple_form.form_items.FormTypes
import com.pradeep.form.simple_form.form_items.NumberInputType
import com.pradeep.form.simple_form.form_items.SingleLineTextType
import com.pradeep.form.simple_form.model.Form

    fun getFormData(): List<Form> {
        val forms = mutableListOf<Form>()
        forms.add(
            Form(
                formType = FormTypes.SINGLE_LINE_TEXT,
                question = "Name",
                hint = "please enter your name",
                singleLineTextType = SingleLineTextType.TEXT,
                errorMessage = "Please provide an answer"
            )
        )
        forms.add(
            Form(
                formType = FormTypes.SINGLE_LINE_TEXT,
                question = "Email",
                hint = "please enter your Email address",
                singleLineTextType = SingleLineTextType.EMAIL_ADDRESS,
                errorMessage = "Please provide a valid email address"
            )
        )
        forms.add(
            Form(
                formType = FormTypes.MULTI_LINE_TEXT,
                question = "Bio",
                description = "tell us about you",
                hint = "I'm from India. I love ice cream.",
                errorMessage = "Please provide an answer"
            )
        )
        forms.add(
            Form(
                formType = FormTypes.SINGLE_CHOICE,
                question = "Gender",
                hint = "please choose your gender",
                choices = listOf(
                    "Male",
                    "Female",
                    "Others"
                ),
                errorMessage = "Please select an answer"
            )
        )

        forms.add(
            Form(
                formType = FormTypes.NUMBER,
                question = "Do you earn or still studying",
                description = "if yes, care to tell us how much you earn per year?",
                numberInputType = NumberInputType.NUMBER,
                errorMessage = "Please provide an answer"
            )
        )
        forms.add(
            Form(
                formType = FormTypes.NUMBER,
                question = "What's  your score in college",
                numberInputType = NumberInputType.DECIMAL_NUMBER,
                errorMessage = "Please provide an answer"
            )
        )
        forms.add(
            Form(
                formType = FormTypes.NUMBER,
                question = "Phone number",
                hint = "please provide your phone number",
                numberInputType = NumberInputType.PHONE_NUMBER,
                errorMessage = "Please provide a valid phone number"
            )
        )
        forms.add(
            Form(
                formType = FormTypes.MULTI_CHOICE,
                question = "Your favourite TV shows",
                description = "you can pick more than one",
                hint = "hint 3",
                choices = listOf(
                    "friends",
                    "tom and jerry",
                    "pokemon",
                    "rick and morty"
                ),
                errorMessage = "Please choose an answer"
            )
        )
        return forms
    }

Step 3:

binding.simpleForm.setData(getFormData(), callback = this)

Step 4:

implement FormSubmitCallback in your activity and override the following function 

    override fun onFormSubmitted(forms: List<Form>) {
         //do something with the result
    }



2. How to create a sectioned form

Alt Text Alt Text Alt Text

Step 1:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <com.pradeep.form.simple_form.SimpleFormView
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

</LinearLayout>

Step 2: (just describe your form item)

import com.pradeep.form.simple_form.form_items.FormTypes
import com.pradeep.form.simple_form.form_items.NumberInputType
import com.pradeep.form.simple_form.form_items.SingleLineTextType
import com.pradeep.form.simple_form.model.Form

fun getSection1FormData(): List<Form> {
      val forms = mutableListOf<Form>()
      forms.add(
            Form(
                formType = FormTypes.SINGLE_LINE_TEXT,
                question = "Name",
                hint = "please enter your name",
                singleLineTextType = SingleLineTextType.TEXT,
                errorMessage = "Please provide an answer"
            )
        )
        forms.add(
            Form(
                formType = FormTypes.SINGLE_LINE_TEXT,
                question = "Email",
                hint = "please enter your Email address",
                singleLineTextType = SingleLineTextType.EMAIL_ADDRESS,
                errorMessage = "Please provide a valid email address"
            )
        )
	forms.add(
            Form(
                formType = FormTypes.NUMBER,
                question = "Phone number",
                hint = "please provide your phone number",
                numberInputType = NumberInputType.PHONE_NUMBER,
                errorMessage = "Please provide a valid phone number"
            )
        )
        return forms
    }

    fun getSection2FormData(): List<Form> {
        val forms = mutableListOf<Form>()
        forms.add(
            Form(
                formType = FormTypes.SINGLE_LINE_TEXT,
                question = "College Name",
                hint = "please enter your name",
                singleLineTextType = SingleLineTextType.TEXT,
                errorMessage = "Please provide an answer"
            )
        )
        forms.add(
            Form(
                formType = FormTypes.NUMBER,
                question = "Your score in college",
                hint = "example: 7.6",
                numberInputType = NumberInputType.NUMBER,
                errorMessage = "Please provide an answer"
            )
        )
        return forms
    }

Step 3:

   private var sectionedForms = mutableMapOf<String, List<Form>>()
   sectionedForms["Personal Information"] = getSection1FormData()
   sectionedForms["Education"] = getSection2FormData()

   binding.simpleForm.setData(sectionedForms, callback = this)

Step 4:

implement FormSubmitCallback in your activity and override the following function 

    override fun onFormSubmitted(forms: List<Form>) {
         //do something with the result
    }




3. How to create a sectioned form and show only one section at a time

note: user can go to next section only after filling all the mandatory fields in the current section

Alt Text Alt Text Alt Text

Step 1:

Create a sectioned form using the 4 steps shown in previous section

Step 2:

after creating a sectioned form, to show one section at a time to user, you can do the following

binding.simpleForm.setData(sectionedForms, callback = this, showOnSectionAtATime = true)

OR

<?xml version="1.0" encoding="utf-8"?>

    <com.pradeep.form.simple_form.SimpleFormView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:showOneSectionAtATime="true" />

simple-form's People

Contributors

lspradeep avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Forkers

talhashahid270

simple-form's Issues

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.