Skip to content

how to show an error in MaterialTextFiel?. #33

Open

Description

@ashishnimbria

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

Activity

  1. Arth1sBack commented on Sep 3, 2020

    @Arth1sBack

    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

  2. PhenomenalMatrix commented on May 14, 2022

    @PhenomenalMatrix

    how to turn off error state

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions