Skip to content

jeroenzonneveld/SwiftUIFormHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

18 Commits
 
 
 
 
 
 
 
 

Repository files navigation

SwiftUIFormHelper

Helper functions for creating forms with SwiftUI

Installation

Swift Package Manager

Once you have your Swift package set up, adding SwiftUIFormHelper as a dependency is as easy as adding it to the dependencies value of your Package.swift.

dependencies: [
    .package(url: "https://github.com/jeroenzonneveld/SwiftUIFormHelper", .upToNextMajor(from: "1.3.1"))
]

Features

  • Helper to create some offset for the keyboard when visible
  • Helper to dismiss the keyboard when pressing on something different then a form field
  • FormValidator to validate input

Create offset for keyboard

Simply add the helper function .enableKeyboardOffset() after a Form.

import SwiftUI 
import SwiftUIFormHelper

Form {

}.enableKeyboardOffset()

Dismiss keyboard on tap

Simply add the helper function .hideKeyboardOnTap() after a Textfield.

import SwiftUI 
import SwiftUIFormHelper

Form {
    TextField("Name", text: $name)
        .hideKeyboardOnTap()
}

Form Validator

Validate input from fields. Currently supported:

  • isNotEmpty
  • isEmpty
  • hasMinimium(characters)
  • isValid
    • email
    • phoneNumber
    • url
import SwiftUIFormHelper

let email = "fake@mailinator.com"
FormValidator.isValid(email: email)

let phoneNumber = "+31612345678"
FormValidator.isValid(phoneNumber: phoneNumber)

let url = "apple.com"
FormValidator.isValid(url: url)