Hi,
I have a form that will have a number of TextFields depending on the data that is passed in. As i need to record what has been entered into these TextFields, i need state vars.
The content is created dynamically but i also need to create the State Vars.
Could someone please explain how this would be done.
This is my code so far.
import SwiftUI
struct CandidateReview: View {
var reviewScore = ["Terrible", "Poor", "Average", "Good", "Excellent"]
var reviewCriterias = ["Communication", "Time Management", "Work Ethic", "Creativity", "Teamwork", "General"]
var candidateName = "John Doe"
@State private var selectedReviewScore = "Average"
@State private var scoreNotes = ""
var body: some View {
NavigationStack{
Form{
ForEach(reviewCriterias, id: \.self) { reviewCriteria in
Section(header: Text(reviewCriteria)){
Picker("\(reviewCriteria) Score", selection: self.$selectedReviewScore){
ForEach(reviewScore, id: \.self){
Text($0)
}
}
NavigationLink(destination:
NavigationView {
Form {
TextField(text: $scoreNotes, label: {})
}.navigationTitle("\(reviewCriteria) review notes")
}
){
Text("This is the text that is shown")
}
}
}
}
.navigationTitle(candidateName)
}
}
}
#Preview {
CandidateReview()
}