Code Monkey home page Code Monkey logo

kformmaster's Introduction

Build status codecov codebeat badge API Android Arsenal Maven Central

This is a Kotlin port of FormMaster

Examples

Full Screen Partial Screen Login
Example Example Example

Documentation

https://thejuki.github.io/KFormMaster

Java Compatibility

  • This library was ported from Java and is still compatible with Java code
  • See Java Example

Installation

NOTE: This library was moved from Bintray/JCenter to Maven Central. The group id is now "com.github.thejuki".

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

ext {
  kFormMasterVersion = [Latest]
}

implementation "com.github.thejuki:k-form-master:$kFormMasterVersion"

Add this to your root build.gradle file:

allprojects {
    repositories {
        mavenCentral()
        google()
        maven { url "https://jitpack.io" }
    }
}

BrowserStack

BrowserStack

The App Automate feature of BrowserStack is used for Espresso testing of this library. The App Automate REST API is used to upload the example app and test app to test multiple devices in parallel.

License

This library is available as open source under the terms of the Apache License, Version 2.0.

kformmaster's People

Contributors

bb-art avatar conrtg avatar dbaelz avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar douglas-srs avatar foodpoison avatar fuhrmann avatar ratulroadzen avatar soareseneves avatar thejuki 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

kformmaster's Issues

Max length for Number input

Hi there,

I want to use the NumberFormField for zip code input. The zip could have maximum 5 digits. Is it possible to set a max value for number felds?

Enable/Disable inputs

Hi there,

great job so far with this kotlin port. I'm looking for a ability to disable and enable input fields. any plans for that?

best,
daniel

Icons for segmented buttons

Hi there,

I do have a great suggestion to improve the design of the forms. There should be a possibility to add an icon (drawable) to a segmented button to archive something like this:

icons

getting `recyclerView must not be null` exception when using Fragment

hey I'm trying to use your plugin inside a tab view, just that on each 3.x version that I tested so far i'm getting the same error:

/AndroidRuntime: FATAL EXCEPTION: main
                  Process: com.maustudios.android, PID: 4330
                  java.lang.IllegalStateException: recyclerView must not be null
                      at com.maustudios.android.AppointmentFragment.setupForm(AppointmentFragment.kt:52)
                      at com.maustudios.android.AppointmentFragment.onCreateView(AppointmentFragment.kt:66)
                      at android.support.v4.app.Fragment.performCreateView(Fragment.java:2346)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1428)
                      at android.support.v4.app.FragmentManagerImpl.moveFragmentToExpectedState(FragmentManager.java:1759)
                      at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1827)
                      at android.support.v4.app.BackStackRecord.executeOps(BackStackRecord.java:797)
                      at android.support.v4.app.FragmentManagerImpl.executeOps(FragmentManager.java:2596)
                      at android.support.v4.app.FragmentManagerImpl.executeOpsTogether(FragmentManager.java:2383)
                      at android.support.v4.app.FragmentManagerImpl.removeRedundantOperationsAndExecute(FragmentManager.java:2338)
                      at android.support.v4.app.FragmentManagerImpl.execPendingActions(FragmentManager.java:2245)
                      at android.support.v4.app.FragmentManagerImpl$1.run(FragmentManager.java:703)
                      at android.os.Handler.handleCallback(Handler.java:790)
                      at android.os.Handler.dispatchMessage(Handler.java:99)
                      at android.os.Looper.loop(Looper.java:164)
                      at android.app.ActivityThread.main(ActivityThread.java:6494)
                      at java.lang.reflect.Method.invoke(Native Method)
                      at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
                      at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
Application terminated.
class AppointmentFragment : Fragment() {
    private lateinit var formBuilder: FormBuildHelper

    private enum class Tag {
        Email,
        Password
    }

    private fun setupForm() {

        val listener = object : OnFormElementValueChangedListener {
            override fun onValueChanged(formElement: BaseFormElement<*>) {

            }
        }

        formBuilder = form(this.context!!, recyclerView, listener, true) {
            header { title = getString(R.string.email) }
            email(Tag.Email.ordinal) {
                title = getString(R.string.email)
                hint = getString(R.string.email)
            }
            password(Tag.Password.ordinal) {
                title = getString(R.string.password)
            }
        }
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val view = inflater.inflate(R.layout.appointment_fragment, container, false)
        this.setupForm();
        return view;
    }


    companion object {
        fun newInstance(): AppointmentFragment = AppointmentFragment()
    }
}

How to reduce margin/padding between fields?

Hi there,

I just tested the new feature "displayDevider = false" from issue #45

It works very well - the divider is gone. But it has left a huge gap between the two form elements. How could I reduce the space between them?

dropDown triggers not the valueChangedListener

Hi there,

im using the OnFormElementValueChangedListener to trigger a save operation if any value of a field changes. With text fields this works very well, but if I change the value of a dropDown the listener is ignored.

I think the value change of a dropDown should trigger the OnFormElementValueChangedListener as well.

Change of background and text color not working

Description

backgroundColor and valueTextColor not working

Expected behavior

backgroundColor = COLOR should change the color of the field to the given one
valueTextColor = COLOR should change input value color to the given one

Actual behavior

backgroundColor = COLOR changes the background to a dirty purple instead of the given one
valueTextColor = COLOR does nothing

Steps to reproduce the bug

Code for form builder

 number(FormField.ZIP) {
                title = "Postleitzahl"
                required = true
                value = "81245"
                numbersOnly = true
                clearable = true
                valueObservers.add { newValue, element ->
                    if(newValue?.length == 5) {
                        zipCode = newValue
                        loadOfflineData()
                    }
                }
            }

Code for changing the color:

formBuilder.getFormElement<FormNumberEditTextElement>(FormField.ZIP).backgroundColor = R.color.offlineDataGreenLight
            formBuilder.getFormElement<FormNumberEditTextElement>(FormField.ZIP).valueTextColor = R.color.offlineDataGreen
            formBuilder.getFormElement<FormNumberEditTextElement>(FormField.ZIP).titleTextColor = R.color.offlineDataGreen

Color-Ressource

<color name="offlineDataGreen">#5cb85c</color>
<color name="offlineDataGreenLight">#eef8ee</color>

KFormMaster version

  • Version: 4.7.0

System information

  • Android OS: 8.1/Latest
  • Issue in Emulator: Yes
  • Issue in physical device: Untested

Support for ListItem

Description

According to the docs, drop down can use a list of ListItems and it should work, however I cannot seem to get it to work when I declare FormPickerDropDownElement.

Why is ListItem not included with the framework if its supported?

Having problems with isValidForm method

First, thanks for this amazing library!

This is my form with 3 simple dropdowns:

val formBuilder = form(context!!, formGeralRecyclerView) {
    dropDown<TipoVisita>(Tag.TipoVisita.ordinal) {
        title = getString(R.string.formace_field_tipovisita)
        options = viewModel.tiposVisitas.toList()
        required = true
        hint = getString(R.string.form_selecione)
    }
    dropDown<Atividade>(Tag.Atividade.ordinal) {
        title = getString(R.string.formace_field_atividade)
        options = viewModel.atividades.toList()
        required = true
        hint = getString(R.string.form_selecione)
    }
    dropDown<Area>(Tag.Area.ordinal) {
        title = getString(R.string.formace_field_area)
        options = viewModel.areas.toList()
        required = true
        hint = getString(R.string.form_selecione)
    }
}

As you noticed, I set required in all of them. Right after the initialization, I tried to validate the form, and I get that the form, even with no values selected, is valid as you can see in the screenshot:

REMOVED

I debugged the FormBuildHelper.isValidForm method and in this piece of code:

!it!!.isHeader and it.isRequired() and (it.value != null)

it returns false for all elements. Maybe I forgot to specifiy something in the field declaration or this is as designed? Shouldn't the isValidForm return false in this case?

The none function as documentation says:

Returns true if no elements match the given [predicate].

Since there are no elements matching the given condition (is not header, is required and the value is not null) the isValidForm returns true, meaning that my form is valid, but it is not.

If I set a predefined value in one of my dropdowns:

REMOVED

dropDown<TipoVisita>(Tag.TipoVisita.ordinal) {
    title = getString(R.string.formace_field_tipovisita)
    options = viewModel.tiposVisitas.toList()
    required = true
    hint = getString(R.string.form_selecione)
   **value = viewModel.tiposVisitas.toList()[0]**
}

The isValidForm returns false:

REMOVED

Change Slider value on sliding

Hi there,

it's really hart for the user to hit the value he wants, when it's not shown.

I think the slider should update its visible value while sliding, so that the user can stop sliding when he reaches the value he wants.

Dealing with validation of free form text

This is more a question looking for ideas.

When I declare a FormMultiLIneEditTextElement, everytime the use enters a character, the listeners fire.

Is there some way to know when they have finished typing? Maybe some sort of out of focus listener which I could use to trigger validation?

Type Radio as Button Group

Hi there,

I'm looking for a way to create a button group which is acting like a custom radio button. So it could by something like a SwitchFormType with more than two switches.

You can find an example attached.

example

ClearAll() not working for FormPickerMultiCheckBoxElement

Description

when I call ClearAll() and then select the element, the dialog is already preset with the previous values.

Expected behavior

no presets set unless value was set in definition of element.

Actual behavior

Previously user-chosen values are set in the dialog

KFormMaster version

  • Version: 4.0.0

Problems with FormMultiCheckBoxElement

Description

I do not see the observers firing when the user has chosen their options.

I'm declaring the element like this:

FormPickerMultiCheckBoxElement()
.setOptions(listOf("A", "B", "C"))
.addValueObserver{ value, element ->
Timber.d("Hello world!!! value: %s", value)
}

Expected behavior

the value observer to fire

Actual behavior

Nothing happens

Steps to reproduce the bug

  1. [First step]
  2. [Second step]
  3. [and so on...]

KFormMaster version

  • Version: 3.2.0

Form element set to visible = false still appears

Hi,

I know I mentioned this before but it has reappeared. I'm looping through the elements, setting them to false but one element still appears. Logcat shows it is being set to false.

Can you have a look because I'm struggling to find a workaround?

You mentioned last time using the dsl but not sure if that will make difference when I want to amend an existing form elements via FormBuilder class.

Suggestion: add an easy way to specify custom layouts per form elements

I'll try to explain my problem.

In my application I have a bunch of forms. Around 13 forms. Its a institutional application, so the forms are required to work within the app.

The first form I did, the field labels and the drop down options were not a problem, they were short and concise. In this second form I'm having a problem as you can see in the two images below.

This first image represents the field label, its not that short:

IMAGE REMOVED

When the user clicks the drop down related to this field, the options are shown:

IMAGE REMOVED

There is no way for me to decrease the length of text (only if I could...). So as you can see they are pretty long. When I select one of this options, I got this result, which is not that pretty and the text is incomplete:

IMAGE REMOVED

The same thing happens when the drop down is multi choice.

So my only way out would be to specify that only in this form, only in drop down fields, I want the formElementValue to be:

android:inputType="textMultiLine"
maxLines="5"

I know there is two other ways:

  • Overwrite the form_element. Downside is that it would be applicable to all forms in my application, to all fields.
  • Create a custom field. My problem with custom fields in this package (not that I don't appreciate your work on this) is that its too much boilerplate code to write.

My idea would be something like this:

textArea(Fields.MyField.ordinal) {
    title = "Ocupation"
    layout = R.layout.my_text_area_layout
}
switch<String>(Fields.MyField.ordinal) {
    title = "This is my title"
    onValue = "Yes"
    offValue = "No"
    layout = R.layout.switch_with_additional_text
}

Or, if we could specify that for only the form being built, something like this:

// Build the form
val formBuilder = form(context!!, my_recycler, cacheForm = true) {
    dropDown<SpinnerOption>(Field.MyField.ordinal) {
        title = "My Field"
        options = listOf()
        hint = getString(R.string.form_selecione)
        dialogTitle = hint

        // Specify custom only for this
        layout = R.layout.special_layout
    }
}


// Specify custom layouts
// Dont mind this sytax, I'm a kotlin beginner
formBuilder.layouts {
	dropDown(R.layout.multiline_dropdown)
	textArea(R.layout.textarea_additional_info)
	text(R.layout.no_text_option)
}

What do you think? Is this something possible to implement? Difficult, maybe?

Reduce margin/padding between fields

Hi there,

I have to reopen the issue #51

There are two problems with the layout solution
1.) I have to remove the title part, too, if I want to reduce the gap to a minimum. This should be more flexible. I should be possible to remove/hide the title/label for each input
2.) Similar problem with the padding. I want to reduce the paddingBottom to 0dp - but only for one single form element and not for all of this type.

I suggest two new options for the form element.

layoutPaddingBottom = 0 // the padding bottom of the LinearLayout
hideTitle = true // if true, the LinearLayout of the formElementTitle will be removed

5.0.2 broken

Hi there,

I can not update my kForm build gradle version anymore. I tried to update from 5.0.0 to 5.0.2 and got some error messages.

It seems like all classes of the library are gone.

  • Unresolved Reference: helper
  • Unresolved Reference: model

I'm using Android Studio 3.2

Example:

Could not find class data for nested class com/thejuki/kformmaster/widget/SegmentedGroup.LayoutSelector of class com/thejuki/kformmaster/widget/SegmentedGroup
Root file: /Users/.../.gradle/caches/transforms-1/files-1.1/k-form-master-5.0.2.aar/a1c0010187862f3d2796bea8a126f8dc/jars/classes.jar!/com/thejuki/kformmaster/widget/SegmentedGroup.class
Dir: /Users/.../.gradle/caches/transforms-1/files-1.1/k-form-master-5.0.2.aar/a1c0010187862f3d2796bea8a126f8dc/jars/classes.jar!/com/thejuki/kformmaster/widget
Children:
ClearableEditText$a.class (valid: true)
ClearableEditText$b.class (valid: true)
ClearableEditText.class (valid: true)
SegmentedGroup$a.class (valid: true)
SegmentedGroup$b.class (valid: true)
SegmentedGroup.class (valid: true)
java.lang.Throwable: Could not find class data for nested class com/thejuki/kformmaster/widget/SegmentedGroup.LayoutSelector of class com/thejuki/kformmaster/widget/SegmentedGroup
Root file: /Users/.../.gradle/caches/transforms-1/files-1.1/k-form-master-5.0.2.aar/a1c0010187862f3d2796bea8a126f8dc/jars/classes.jar!/com/thejuki/kformmaster/widget/SegmentedGroup.class
Dir: /Users/.../.gradle/caches/transforms-1/files-1.1/k-form-master-5.0.2.aar/a1c0010187862f3d2796bea8a126f8dc/jars/classes.jar!/com/thejuki/kformmaster/widget
Children:
ClearableEditText$a.class (valid: true)
ClearableEditText$b.class (valid: true)
ClearableEditText.class (valid: true)
SegmentedGroup$a.class (valid: true)
SegmentedGroup$b.class (valid: true)
SegmentedGroup.class (valid: true)
at com.intellij.openapi.diagnostic.Logger.error(Logger.java:126)
at org.jetbrains.kotlin.idea.decompiler.stubBuilder.ClassClsStubBuilder.createNestedClassStub(ClassClsStubBuilder.kt:253)
at org.jetbrains.kotlin.idea.decompiler.stubBuilder.ClassClsStubBuilder.createInnerAndNestedClasses(ClassClsStubBuilder.kt:244)
at org.jetbrains.kotlin.idea.decompiler.stubBuilder.ClassClsStubBuilder.createClassBodyAndMemberStubs(ClassClsStubBuilder.kt:187)
at org.jetbrains.kotlin.idea.decompiler.stubBuilder.ClassClsStubBuilder.build(ClassClsStubBuilder.kt:96)
at org.jetbrains.kotlin.idea.decompiler.stubBuilder.ClassClsStubBuilderKt.createClassStub(ClassClsStubBuilder.kt:55)
at org.jetbrains.kotlin.idea.decompiler.stubBuilder.ClsStubBuildingKt.createTopLevelClassStub(clsStubBuilding.kt:53)
at org.jetbrains.kotlin.idea.decompiler.classFile.KotlinClsStubBuilder.doBuildFileStub(KotlinClsStubBuilder.kt:86)
at org.jetbrains.kotlin.idea.decompiler.classFile.KotlinClsStubBuilder.buildFileStub(KotlinClsStubBuilder.kt:52)
at com.intellij.psi.impl.compiled.ClassFileStubBuilder.buildStubTree(ClassFileStubBuilder.java:45)
at com.intellij.psi.impl.compiled.ClassFileStubBuilder.buildStubTree(ClassFileStubBuilder.java:25)
at com.intellij.psi.stubs.StubTreeBuilder.buildStubTree(StubTreeBuilder.java:61)
at com.intellij.psi.stubs.StubUpdatingIndex$3.lambda$map$0(StubUpdatingIndex.java:232)
at com.intellij.openapi.application.impl.ApplicationImpl.runReadAction(ApplicationImpl.java:897)
at com.intellij.psi.stubs.StubUpdatingIndex$3.map(StubUpdatingIndex.java:214)
at com.intellij.psi.stubs.StubUpdatingIndex$3.map(StubUpdatingIndex.java:197)
at com.intellij.util.indexing.impl.MapReduceIndex.mapInput(MapReduceIndex.java:273)
at com.intellij.util.indexing.VfsAwareMapReduceIndex.calculateUpdateData(VfsAwareMapReduceIndex.java:96)
at com.intellij.util.indexing.impl.MapReduceIndex.update(MapReduceIndex.java:213)
at com.intellij.util.indexing.FileBasedIndexImpl.updateSingleIndex(FileBasedIndexImpl.java:1687)
at com.intellij.util.indexing.FileBasedIndexImpl.lambda$doIndexFileContent$21(FileBasedIndexImpl.java:1615)
at com.intellij.openapi.fileTypes.impl.FileTypeManagerImpl.freezeFileTypeTemporarilyIn(FileTypeManagerImpl.java:523)
at com.intellij.util.indexing.FileBasedIndexImpl.doIndexFileContent(FileBasedIndexImpl.java:1574)
at com.intellij.util.indexing.FileBasedIndexImpl.indexFileContent(FileBasedIndexImpl.java:1562)
at com.intellij.util.indexing.UnindexedFilesUpdater.lambda$indexFiles$0(UnindexedFilesUpdater.java:116)
at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.lambda$run$0(CacheUpdateRunner.java:230)
at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1137)
at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.lambda$run$1(CacheUpdateRunner.java:246)
at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$1(CoreProgressManager.java:157)
at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:580)
at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:525)
at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:85)
at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:144)
at com.intellij.openapi.project.CacheUpdateRunner$MyRunnable.run(CacheUpdateRunner.java:243)
at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:305)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

Logo Proposal for KFormMaster

Hi, I'm a graphic designer and I like to collaborate with open source projects. Do you know that the graphic image of a project is very important? thinking about it I would like to design a logo for your Project KFormMaster.

I will be pleased to collaborate with you.

ListItem and ContactItem classes

Description

ListItem.tk and ContactItem.tk are only defined in the examples package and one test folder, but they are used in the docs. If one only adds the library as a dependency, none of the two classes are available.

Expected behavior

If I copy a snippet from the docs, I expect it to work.

Actual behaviour

The classes cannot be found. I've copied them to my project's src and that solves the issue, but it seems odd to have to do that. If they are core, they should be in the core library, if not, maybe use some alternative examples?
I don't know what the right thing to do is here, but at a minimum, indicate in the docs that this will happen. ListItem is used in several places in the docs, but unless I am missing it, I don't see any indications of this.

Steps to reproduce the bug

  1. Start a fresh project with the library as a dependency
  2. Copy dropdown examples from the docs as:
  dropDown<ListItem>(1) {
      dialogTitle = "Select One"
      options = listOf(ListItem(id = 1, name = "Banana"), 
                       ListItem(id = 2, name = "Orange"))
      value = ListItem(id = 1, name = "Banana")
  }
  1. Figure out what to do with the imports that do not resolve.

KFormMaster version

  • Version: 5.0.0

System information

  • Android OS: 8.1
  • Issue in Emulator: Yes
  • Issue in physical device: Untested

Thanks!

Ability to change background and text color of input

Hi there,

I'm still working on my zip code input field. I want to change the background color to a light green and the text color to a dark green if the entered zip code matches my post data. If the zip code is invalid I want to change it to red.

I imagined something like
formBuilder.getFormElement<FormNumberEditTextElement>(FormField.ZIP).setBackgroundColor(...)

Any idea to make this happen?

Element is visible even though set to invisible

Description

[Description of the bug]

My form is meant to display questions one by one as a user answers them.

I accomplish this by building the form and its elements and setting visibility to false (line 153). Then I go through and explicitly enable the first question (line 182).

However, what I am seeing is that Question 3 (tag 3) is visible. The logcat output in the image shows Element with tag 3 is set INVISIBLE (visible = false).

Playing around, if i set tag 3 manually to invisible (line 183) it will disappear.

Expected behavior

elements set to visible = false are not shown

Actual behavior

an element set to visible = false is shown on the UI

Steps to reproduce the bug

KFormMaster version

  • Version: 4.0.1

System information

  • Android OS: 8.1/Latest
  • Issue in Emulator: Yes/No/Untested
  • Issue in physical device: Yes/No/Untested

Option for "clear input on tab"

Hi there,

I think it could be a good idea to provide an option to clear an input field, when the user tabs in.

My app, for example, has a input field for adding a zip code. It's prefilled with the zip of the users current location - but he should be able to change it at any time.

For now, the user has to clear the value by himself or press the "X" if I enabled the "clearable" option. But both steps are one stept to much for a great usability. If the user tabs into the field, we already know that he wants to add a new value, so it should be possible to clear it directly.

Access to inputType

Hi, is there some way to set this value without creating my own custom component?

Listener called for non-modified text fields

Thanks for the great library!

I hope you can help me with an issue, the listener is called on an element that is not modified.
I've checked the implementation and I cannot figure why the listener is called on the non-modified field.

Thanks in advance for any tips or advice

This is my setup:


private enum class PTag {
            P_NAME,
           // ... other tags
            DOC_NAME,
        }

formBuilder = form(this.context!!, recyclerView, listener) {

                header { title = "Patient Info" }
                text(PTag.P_NAME.ordinal) {
                    title = "Name"
                    value = prefs!!.getString(PTag.P_NAME.name, "")
                }
               header { title = "Doctor Info" }
                text(PTag.DOC_NAME.ordinal) {
                    title = "Doctor Name"
                    value = prefs!!.getString(PTag.DOC_NAME.name, "")
                }

error

Request: ability to intercept touch event

Hi,

I have been given a requirement where a previously completed question is edited, that the user see a message first to confirm they wish to edit the field.

Currently, the only listener is after they have chosen a value, I show a dialog asking them to confirm the change and then manually set the value to the old value if they say cancel.

Edit: If i set the value back because they chose cancel, won't the listener fire again putting me in a loop?

How do remove divider from Form-Items

Hi there,

I want to remove the divider from my form items. Usally I use the following code to remove the lines from the recycler view.

recyclerView?.addItemDecoration(DividerItemDecoration(context, 0))

But in combination with the forms it does'nt work. Maybe the formbuilder places its own ItemDecoration?

Segmented control value not getting triggered

Description

Segmented Control value observer nor the value of the segmented control is not getting triggered when clicked for the first time(empty form), any further clicks on the value selected first also doesn't seem to trigger the value change, it works properly if i set a initial value though.

Expected behaviour

The value should change when selection a segment for the first time even though the segment element initial value is null

Actual behaviour

The value of the segmented control is not getting triggered when clicked for the first time.

Steps to reproduce the bug

  1. Setup a segmented control without any initial value
  2. Add value observer
  3. Click on any segment, the value wont be changed even though a button has been clicked

KFormMaster version

Version: Latest

DropDownBuilder see the preselected value

Hello,

I would like to ask if there is possible to show the preselected value of DropDownBuilder with tick or something, to know what was chosen before opening DropDownBuilder. (Of course, if there was no chosen value before there is no need to show any tick).

screenshot_1538225761

Thank you very much!

LabelRow inside the form

I'm trying at this moment to create a complex form where most of the processing is happening on the server.

One way to show the errors of form elements it's to use a LabelRow (I already achieved this with Eureka form on iOs), but if you have something similar please let me know, otherwise I already started on implementing something similar (maybe I can add it to your project as a basic component)

Allow user to change gravity of text control elements

Right now (at least with Spanish locale) text control elements align their values to the right, which may be weird for users when introducing text, especially in controls that allow more than one line of text.

I think that this behaviour is controlled by the attribute gravity of formElementValue in form_element_custom.xml, which is set to end.

Can this be customized in code? Or else, could you add some way to change it?

Thanks in advance!

Can't change segmented list item (option) on runtime

Hi there,

I do have a simple segmented form element which looks like this

var squareMeterList = listOf(
                                   SquareMeterListItem(id = 1, name = "30 m²", usage = "1250"),
                                   SquareMeterListItem(id = 2, name = "50 m²", usage = "2500"),
                                   SquareMeterListItem(id = 3, name = "100 m²", usage = "5000"),
                                   SquareMeterListItem(id = 4, name = "150 m²", usage = "9000")
                           )
segmented<SquareMeterListItem>(FormField.USAGE_BUTTONLIST) {
                options = squareMeterList
                value = squareMeterList[1]
}

Now I want to replace the segmented list with a new one at runtime. This is the code:

var squareMeterListNew = listOf(
                                   SquareMeterListItem(id = 1, name = "30 m²", usage = "6000"),
                                   SquareMeterListItem(id = 2, name = "50 m²", usage = "10000"),
                                   SquareMeterListItem(id = 3, name = "100 m²", usage = "20000"),
                                   SquareMeterListItem(id = 4, name = "150 m²", usage = "36000")
                           )
formBuilder.getFormElement<FormSegmentedElement<SquareMeterListItem>>(FormField.USAGE_BUTTONLIST).options = squareMeterListNew

But the app crashes with this error:

java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.Object android.content.Context.getSystemService(java.lang.String)' on a null object reference
at android.view.LayoutInflater.from(LayoutInflater.java:229)
at com.thejuki.kformmaster.model.FormSegmentedElement.reInitGroup(FormSegmentedElement.kt:174)
at com.thejuki.kformmaster.model.FormSegmentedElement.reInitGroup$default(FormSegmentedElement.kt:167)
at com.thejuki.kformmaster.model.FormSegmentedElement.setOptions(FormSegmentedElement.kt:61)

I would expect that the segmented button element will be rebuilded with the new options.

Remove elements dynamically

Hi, first of all congrats for your library. Forms are always bored, at least for me and your library just makes things easier.

Is it currently possible to remove elements dynamically? I'm already using addElement/addElements to add items to the form, but i'm not sure if an opposite function currently exists. If it does not, it would be nice.

Thanks in advance =)

Steps in Slider not working

Description

The slider ignores the declared steps

Expected behavior

If I declare steps = 50 I expect, that the slider snaps in 50-steps... ex. 0, 50, 100, ..., 500, 550, 600, ...

An value of 49 or 113 should not be possible.

Actual behavior

The slider does not snap to any divisor of 50. A value of 49 or 113 can be selected.

Steps to reproduce the bug

  1. create slider
    slider(1) {
    steps = 50
    min = 100
    max = 1000
    }

  2. slide the slider to any position

  3. = no divisor of 50 selected

KFormMaster version

  • Version: Latest

System information

  • Pixel 2 XL
  • Android OS: 8.1
  • Issue in Emulator: Yes
  • Issue in physical device: Untested

Changing dropDown options dinamically while form is cached

Since issue #16 is happening, I always have to create a form and set cacheForm to true. But this way, I can't change the options of a drop down dynamically.

These are the steps my form implements:

  • User select OPTION1 from DROPDOWN1
  • Application set options of DROPDOWN2 to (A, B, C)
  • User select OPTION2 from DROPDOWN1
  • Application set options of DROPDOWN2 to (A, B)

Since the form is cached, the options are not being updated. If you need a gif of this happening, let me know (or need any help)!

Maybe you could give us a method that we can manually invalidate the options of a cached dropdown something like this:

// If the form is cached, we have to manually call invalidate
val items = ...
val dropdown = getFormElement<FormPickerDropDownElement<MyItem>>(Fields.Field1)
dropdown.setOptions(items)
dropdown.invalidate()

I think this is good, because in my case I want my form to be cached, because it's too many fields. But I want the possibility of changing everything dinamically. Does this makes sense for you?

Thanks.

SegmentedListItem: Drawable should fit size

Hi there,

the SegmentedListItem with a drawable works great so for. But if I set the name to null there is a huge space left below the icon.

Better:
If there is no name set for the button, the drawable should use the additional space and scale to fit.

icons2

FormPasswordEditTextElement Field is always empty

I'm playing with the password field on finishing the register view

Just that the FormPasswordEditTextElement is always empty when I try to retrieve the field value.

when check if the form is valid:

formBuilder.elements.forEach({
                    if (!it.isValid) {
                        it.error = "This field is required!"
                    }
                })

It always shows that the field is empty

And the same thing I also get when I try to access the field manually via the line:
val passwordElementValue = formBuilder.getFormElement(Tag.Password.ordinal).value as String?
or
When I'm checking it via the debugger.

Any tips on where to check this because I was looking at the code to submit a PR but I couldn't find anything so far

Issue with recycler view recycling?

This is part of my form (it has more fields):

number(Field1.ordinal) {
    title = getString(R.string.field_1)
    hint = getString(R.string.select)
    required = true
}
number(Field2.ordinal) {
    title = getString(R.string.field_2)
    numbersOnly = true
    hint = getString(R.string.select)
    required = true
}

I set to not cache the form:

val formBuilder = form(this, recycler_fields, cacheForm = false) {

And I got this result:

REMOVED

If I set cacheForm to true everything works fine,

This is the layout of my form activity:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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

</LinearLayout>

Is this maybe related to the way recycler works?

Disabling form elements

Hi,

I'm building a dynamic form and once a user has answered a question, I would like to make that question uneditable.

How would I accomplish this? I can tell if they have answered the question before but not sure what property to set on the elemnts. I tried options = listOf() but that didn't work, the original options still appeared.

Cannot use the set methods from the element models in Java

Description

Cannot use the set methods from the element models in Java.

Expected behavior

No compiler errors.

Actual behavior

Ambiguous method call setBackgroundColor (Integer) in BaseFormElement and setBackgroundColor (Integer) in BaseFormElement match

Steps to reproduce the bug

Use any set method from any element models in Java

KFormMaster version

  • Version: Latest

System information

  • Android OS: Latest
  • Issue in Emulator: Yes
  • Issue in physical device: Yes

actionNext issue with multiple EditText and headers

Hey! I'm having a issue with the 'actionNext', take a look at this example:

REMOVED

As I'm typing and pressing the next arrow, I'm redirected to the next input, but sometimes the focus is lost.
My form is basically a bunch of headers and numbers:

header {
    title = getString(R.string.mystring)
}
number(MyField.ordinal) {
    numbersOnly = true
    title = getString(R.string.mystring2)
}

It looks like when the fields are not visible, android cant put focus on the next field, something like that? I don't know. I wrote "actionNext" in the title of this issue because I saw that your form_element has this imeOptions:

android:imeOptions="actionNext"

Question about AppCompatActivity

Description

This may not be a bug as such, but I tried to integrate the library a couple of times in an existing project and couldn't make it work (until now!) so just wanted to ask if this is a known issue, or is it documented somewhere that I did not check or see?

The issues is the following: I can see the list of form elements, but only the labels (no checkboxes or any other elements) and I cannot click or edit anything.

It turns out that when I switch from Activity to AppCompatActivity, all starts working normally. This does not happen with Fragments, I do not need to use the v4 compat version of that class, it works fine with a normal Fragment, but it does happen with Activity.

Expected behavior

I would expect this to either work with an Activity class, or be documented somewhere (which may already be, but I have not found where).

Actual behavior

As explained earlier, when creating a form in an Activity, only the labels appear, and elements are not clickable, or editable or anything.

Steps to reproduce the bug

Follow the getting started guide but use and Activity instead of an AppCompatActivity class.

KFormMaster version

  • Version: tested with 4.5.0 and 4.5.1

System information

  • Android OS: 8.1
  • Issue in Emulator: Yes
  • Issue in physical device: Untested

Issue with DatePicker

Hi,

it looks like DatePicker adds a month to the value shown in the form. I.e. if you pick march 15th 2018 it'll show 6/15/2018 instead of 5/15/2018, but if you tap again the control the picker'll show the correct value.

Maybe this has to do with the lines 54 and 78 of FormPickerDateViewBinder.kt?

Change the visibility and required dinamically

Okay, so I did use the valueObservers to know when a specific field in my form changes. This is my actual code:

valueObservers.add({ newValue, element ->
    if (!newValue!!.isEmpty()) {
        val larvicida = getFormElement(Tag.TipoLarvicida.ordinal)
        val value = newValue.toInt()

        larvicida!!.required = value > 0
        larvicida.visible = value > 0
    }
})

If there is a value I want the field TipoLarvicida to be visible and required. If not, I want to hide it and its not required anymore. My problem is that after setting the required and visible I have to call refreshView so the before invisible field now appears on the screen.

It works fine, but the problem is that the focus on the field is lost and among other stranger things happens:

REMOVED

My recycler view already have the:

android:descendantFocusability="beforeDescendants"

Ive tried using afterDescendants, but no success. But as you can see in the gif, there are certain fields that are populated automatically, for some reason!

Here is my complete code of my form if it helps: https://gist.github.com/Fuhrmann/3ede5273708dda055e4e4618538b2264#file-formbuilder-java-L71

And at the end I get this error while typing too fast at the input:

Cannot call this method while RecyclerView is computing a layout or scrolling android.support.v7.widget.RecyclerView{843e5e VFED..... ......ID 0,0-1080,914 #7f080057 app:id/formTratamentoRecyclerView}, adapter:com.github.vivchar.rendererrecyclerviewadapter.RendererRecyclerViewAdapter@e03623f, layout:android.support.v7.widget.LinearLayoutManager@b1a370c, 

Maybe is there another way to refresh the view?

Validation and Error examples

Description

Not a bug as such, I believe I am just not using it correctly.

Expected behavior

If I have an element and a button like:

      text {
        title = getString(R.string.city)
        hint = "city"
        required
        maxLength = 2
      }
      button {
        value = "Submit"
        valueObservers.add { _, _ ->
          if (formBuilder.getElementAtIndex(0).isValid) {
            toast("form is valid!")
          }
          else {
            toast("form is not valid!")
          }
        }
      }

I would expect that the form is not valid if I type nothing in the text field. But it always goes through.
formBuilder.isValidForm seems to also be always true.

With errors, when I have an element like this:

      text {
        title = getString(R.string.city)
        hint = "city"
        error= "This is the error message"
        required
        maxLength = 2
      }

I see the error message in red when the form loads, but after that, even if the field is changed and then emptied again, the error message goes away and never comes back.

So I believe I am doing something wrong, or not understanding how this works. I have tried using the values inside and outside of observers, but can't get any proper validation working.

Any help would be greatly appreciated.

KFormMaster version

  • Version: 5.0.0

System information

  • Android OS: 8.1 on emulator
  • Issue in Emulator: Yes
  • Issue in physical device: Untested

Field with custom inputType (TYPE_CLASS_NUMBER only!)

I really like the idea of having custom elements and it works great! Thanks. I want to have a number() input, but I don't want to allow any symbols (.,-), only numbers.

To achieve this I can create a custom element and set the inputType of the editText to:

editTextValue.inputType = InputType.TYPE_CLASS_NUMBER

inside my ViewBinder.

For this to work, I have to create 4 classes:

  • FormBuilderExtensions -> to register my custom method
  • OnlyNumbersElement
  • OnlyNumbersViewBinder
  • OnlyNumbersViewState

The problem: analyzing all the code written to make it work, in the end I changed only one line:

The original FormNumberEditTextViewBinder:

editTextValue.setRawInputType(InputType.TYPE_CLASS_NUMBER or InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS)

My custom element:

editTextValue.inputType = InputType.TYPE_CLASS_NUMBER

I mean, could be a better way to specify a custom inputType or even better, a custom setOnFocusChangeListener? Or I don't know, a way so we can have access to the editTextValue inside our activity?

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.