Post

Replies

Boosts

Views

Activity

Add TextFields inside a Form in MacOS SwiftUI
I want to build a MacOS form that allows for the end user to add textfields in the same way one can add rows to an excel table. The reason I want to use textfields is because I can't seem to find an example of a Table that will allow me to add text.  I managed to get a basic setup using 'ForEach' and a button to append, however, when running the app from Xcode I am getting an error:  "the ID  occurs multiple times within the collection, this will give undefined results!" I realise that setting up unique ID's for each field is necessary, but I don't know how to set this up where the number of textfields that the end user will add can vary per form, and they are based on the append action. I even considered using the new 'GridRow' but it is only available for MacOS13 and above, and until Apple roles out with Ventura in late October I cannot implement this in the app. (no I do not want to run Ventura Beta as the machine this app will run on will only update MacOS when it officially roles out) Here is my code:  import SwiftUI struct ContentView: View {     @State private var name: [String] = []     @State private var address: [String] = []     @State private var telephoneNumber: [String] = []     var body: some View {         HStack {             VStack{                 ForEach($name, id: \.self) {$name in TextField("Name", text:$name)                 }                 Button(action: {                     name.append("")                 }) {                     Text("Add Name")                     Image(systemName: "plus.circle.fill")                         .foregroundColor(Color(.systemGreen))                 }             }             .padding()             VStack {                 ForEach($address, id: \.self) {$address in TextField("Address", text:$address)                 }                 Button(action: {                     address.append("")                 }) {                     Text("Add Address")                     Image(systemName: "plus.circle.fill")                         .foregroundColor(Color(.systemGreen))                 }             }             .padding()             VStack {                 ForEach($telephoneNumber, id: \.self) {$telephoneNumber in                     TextField("Telephone Number", text: $telephoneNumber)                 }                 Button(action: {                     telephoneNumber.append("")                 }) {                     Text("Add Telephone Number")                     Image(systemName: "plus.circle.fill")                         .foregroundColor(Color(.systemGreen))                 }             }             .padding()         }         Spacer()         .frame(width: 600, height: 600)     } } struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()     } } What is more is that when I type in one of the textfields, take 'name' textfield as an example, the additional 'name' textfields below are populated with the same text, and the textfield loses its focus after one letter is typed.  Please will someone give me some guidance on how to correct this such that all additional textfields created are given a unique ID and save to the Form.
3
0
980
Aug ’22
Export MacOS SwiftUI form to pdf
I am building a MacOS dedicated app where I want to build a document template using a form. Inside the form there are multiple data types: text, pickers, images, links to other pdfs and signatures. I want to be able to export the data in the form to pdf, retaining the formatting of the form. I have searched high and low for some sort of solution, where PDFKit and Quartz seem to come up but no viable solution. This really should not be a complex process... And I do not want to use storyboard but only use SwiftUI.
1
0
590
Aug ’22
MultiPart Form uploads and Automation
Hello Devs and Support, I am a new developer with a challenge to build a MacOS app that captures preliminary data from clients (text, signatures, jpgs and pdfs) and then pulls that data into a database where a secondary app automatically extracts the data into a word document template. I have been researching to find documentation and support on how to implement this using SwiftUI and have only managed to build a basic content view: //  ContentView.swift //  Client Form // //  Created by Andrew Duncan Poole on 2022/05/10. // import SwiftUI struct ContentView: View {     @State var firstName = ""     @State var lastName = ""     @State var companyName = ""     @State var isExchange: Bool = true     @State var description = "This book is about .."     @State var price = ""     @State private var scrollViewContentSize: CGSize = .zero     @State private var categoryIndex = 0     var categorySelection = ["Action", "classic","Comic Book","Fantasy","Historical","Literary Fiction","Biographies","Essays"]               var body: some View {         ScrollView(.horizontal, showsIndicators: true) {             HStack (spacing: 1) {                          Form {                              Section(header: Text("CE Technical File Preliminary Data")) {                     TextField("First Name", text: $firstName)                     TextField("Last Name", text: $lastName)                     TextField("Company Name", text: $companyName)                     Toggle(isOn: $isExchange) {                         Text("I'm interested in an exhange")                     }                     .frame(width: 650)                 }                          Section() {                 Picker(selection: $categoryIndex, label: Text("Categorie")) {                     ForEach(0 ..< categorySelection.count) {                         Text(self.categorySelection[$0])                     }                 }             }             Section(header: Text("Description")) {                 TextEditor(text: $description)             }                          Section {                 Button(action: {                     print("submitted ..")                 }) {                     Text("Publish now")                 }             }         }                                       }.navigationTitle("Simplimedica Client Form")             }         }      struct ContentView_Previews: PreviewProvider {     static var previews: some View {         ContentView()         }     } } Is there anyone who can PLEASE advise where I can find further assistance be it tutorials or sample code for this...
2
0
1.1k
May ’22
Document Process Automation MacOS Application Development
I need two applications: a document process automation application to pull preliminary data from multiple document types (pdfs, doc, xlsx, jpg) into a word document template a mobile application form that my clients can submit their preliminary data and direct this data into the client specific word document template Does anyone know of an existing MacOS native app that runs offline and can fulfil my requirements? If not, do you have any pointers for tutorials please..
0
0
281
Apr ’22