Repository Public MIT
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// Project : SP GlassKit7// File : Examples/Gallery/Forms/GlassTextFieldExample.swift8// Module : Examples9// Repository : https://git.spboucher.ai/sp-glasskit10// Project Website : https://glass.spboucher.ai11// Created : 2026-12-0212// Last Modified : 2026-12-0313//14// Author : Simon-Pierre Boucher15// Position : Professor of Finance16// Institution : Université du Québec en Outaouais (UQO)17// Organization : SP Boucher18// Website : https://spboucher.ai19// Git : https://git.spboucher.ai20//21// Preferred Contact: contact@spboucher.ai22// Development : dev@spboucher.ai23// Support : support@spboucher.ai24// Security/Admin : admin@spboucher.ai25//26// Copyright (c) 202627// Simon-Pierre Boucher28// All rights reserved where applicable. This file is governed by the29// applicable project license, copyright notices and relevant law.30// Existing third-party rights and notices remain unaffected.31//32// License : MIT33//34// Do not embed credentials, private keys, access tokens,35// certificates or confidential personal information.36//37// =============================================================================38// END OF SP BOUCHER SOURCE HEADER39// =============================================================================4041import SwiftUI42import SPGlassKit4344public struct GlassTextFieldExample: GlassExample {45 public static let componentID = "glass-text-field"46 @State private var name = ""47 @State private var email = ""48 @State private var handle = "taken"49 @State private var locked = "Read-only value"50 @FocusState private var emailFocused: Bool5152 public init() {}5354 public var body: some View {55 ScrollView {56 VStack(alignment: .leading, spacing: 20) {57 GlassTextField(58 "Full name",59 text: $name,60 prompt: "Ada Lovelace",61 validation: GlassFieldValidation(.required(), .minLength(2)),62 input: .name63 )64 .onSubmit { emailFocused = true }6566 GlassTextField(67 "Email",68 text: $email,69 prompt: "name@example.com",70 helper: "Used only for the receipt.",71 systemImage: "envelope",72 validation: GlassFieldValidation(.required(), .custom(message: "Enter an address such as name@example.com") { $0.contains("@") && $0.contains(".") }),73 input: .email,74 focus: $emailFocused75 )7677 GlassTextField(78 "Username",79 text: $handle,80 validation: GlassFieldValidation(.maxLength(12)),81 validateOn: .always,82 errorMessage: handle == "taken" ? "This username is already taken." : nil,83 input: .username84 )8586 GlassTextField("Account", text: $locked)87 .disabled(true)8889 Button("Focus the email field") { emailFocused = true }90 }91 .padding()92 }93 }94}9596#Preview("GlassTextField") { GlassTextFieldExample().glassTheme(.aurora) }97