Disabling and enabling items in forms
Form fields may have additional requirements such as minimum text length or a combination of uppercase and lowercase characters. We may want to perform actions based on the user's input, such as disabling a Submit button till all requirements are met.
In this recipe, we will create a sign-in view where the Submit button only gets enabled if the user enters some content in both the username and password fields.
Getting ready
Create a SwiftUI project called FormFieldDisable
.
How to do it…
We will create a login screen containing a username, password, and a Submit button. We will disable the Submit button by default and only enable it when the user enters some text in the username and password fields. The steps are given here:
- Create a new SwiftUI view file named
LoginView
:a. Press Command () + N.
b. Select SwiftUI View.
c. Click Next.
d. Enter
LoginView
in the Save as field.e. Click Finish.
- Open the
LoginView.swift...