Disabling/enabling items in a form
Forms may contain required and optional fields. Some fields may have additional requirements that need to be met. For example, the password fields may be required to contain at least eight characters. When developing an app, we may want to enable or disable the submit button based on the form requirements, thus allowing the users to submit a form only when it meets all our requirements.
In this recipe, we will create a sign-in page where the submit button gets enabled only if the user enters some content in the username and password fields.
Getting ready
Create a SwiftUI project and name it FormFieldDisabable
.
How to do it…
We will create a SwiftUI view with a username field, password field, and a submit button. The submit button will be disabled unless the user enters some text in the username and password fields. The steps are as follows:
- Create a new SwiftUI view file named
LoginView
:a. Press ⌘ + N.
b. Select...