Skip to content

Latest commit

 

History

History
65 lines (49 loc) · 2.13 KB

dialog-input.md

File metadata and controls

65 lines (49 loc) · 2.13 KB

Dialog Input Module

Input Dialog
Dialog

This module is placed inside the dialogs-input artifact and the main definition looks like following:

class DialogInput(
// Key
override val id: Int? = null,
// Header
override val title: Text = Text.Empty,
override val icon: Icon = Icon.None,
override val menu: Int? = null,
// specific fields
val description: Text = Text.Empty,
val input: Input,
val selectAllOnFocus: Boolean = false,
// Buttons
override val buttonPositive: Text = MaterialDialog.defaults.buttonPositive,
override val buttonNegative: Text = MaterialDialog.defaults.buttonNegative,
override val buttonNeutral: Text = MaterialDialog.defaults.buttonNeutral,
// Style
override val cancelable: Boolean = MaterialDialog.defaults.cancelable,
// Attached Data
override val extra: Parcelable? = null
) : MaterialDialogSetup<DialogInput, MdfContentInputBinding, DialogInput.Event>() {

This dialog will emit events of the sealed class type DialogInput.Event that looks like following:

sealed class Event : IMaterialDialogEvent {
data class Result(
override val id: Int?,
override val extra: Parcelable?,
val inputs: List<String>,
val button: MaterialDialogButton
) : Event() {
val input: String
get() = inputs[0]
}
data class Action(
override val id: Int?,
override val extra: Parcelable?,
override val data: MaterialDialogAction
) : Event(), IMaterialDialogEvent.Action
}

Tipps

Input Type

This dialog allows to get any insert from the user. You can limit the input type by providing a custom android.text.InputType flag. E.g. like following:

 DialogInput(
    ...
    input = DialogInput.Input.Single(
        inputType = InputType.TYPE_CLASS_NUMBER // only allow numerical input
    )
    ...
)

Multiple Inputs

This dialog allows you to display multiple inputs as well like following:

 DialogInput(
    ...
    input = DialogInput.Input.Single(
        input = DialogInput.Input.Multi(
            listOf(
                DialogInput.Input.Single(hint = "Value 1".asText()),
                DialogInput.Input.Single(hint = "Value 2".asText()),
                DialogInput.Input.Single(hint = "Value 3".asText()),
            )
        )
    )
    ...
)

Input Validator

You can find the interface here. If desired you can implement this interface in your custom class and provide whatever logic you want.

A simple default implementation is already added and you can create instances of it like following:

 DialogInput(
    ...
    input = DialogInput.Input.Single(
        validator = DialogInput.TextValidator(minLength = 1, maxLength = 10) // force the length to be in the range [1, 10], both lengths are nullable to disable an enforcement on each side if desired
    )
    ...
)