MaterialTextField icon indicating copy to clipboard operation
MaterialTextField copied to clipboard

how to show an error in MaterialTextFiel?.

Open ashishnimbria opened this issue 4 years ago • 2 comments

I am not able to show an error. Could you please provide me an example.

ashishnimbria avatar Jun 12 '20 11:06 ashishnimbria

Here's my suggestion :

Start by defining your own error type like :

enum TextFieldError: Error {
    case emptyTextField
}

extension TextFieldError: LocalizedError {
    public var errorDescription: String? {
        switch self {
        case .emptyTextField:
            return "Here, the string you want to display below the text field"
        }
    }
}

Then, you can use later it as :

if titleTextField.text == "" {
       let error: Error = TextFieldError.emptyTextField
       titleTextField.setError(error, animated: true)
}

Hope it will help

Arth1sBack avatar Sep 03 '20 12:09 Arth1sBack

how to turn off error state

PhenomenalMatrix avatar May 14 '22 05:05 PhenomenalMatrix