allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
dependencies {
implementation 'com.github.lspradeep:simple-form:v1.0.1'
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://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>
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
}
binding.simpleForm.setData(getFormData(), callback = this)
implement FormSubmitCallback in your activity and override the following function
override fun onFormSubmitted(forms: List<Form>) {
//do something with the result
}
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="https://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>
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
}
private var sectionedForms = mutableMapOf<String, List<Form>>()
sectionedForms["Personal Information"] = getSection1FormData()
sectionedForms["Education"] = getSection2FormData()
binding.simpleForm.setData(sectionedForms, callback = this)
implement FormSubmitCallback in your activity and override the following function
override fun onFormSubmitted(forms: List<Form>) {
//do something with the result
}
note: user can go to next section only after filling all the mandatory fields in the current section
binding.simpleForm.setData(sectionedForms, callback = this, showOnSectionAtATime = true)
<?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" />