Skip to content

Commit

Permalink
[#33] Add multi text form
Browse files Browse the repository at this point in the history
  • Loading branch information
blyscuit committed Feb 7, 2023
1 parent 3a17545 commit 80cfc71
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
4 changes: 4 additions & 0 deletions iosApp/Survey.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,7 @@
09E08C5A2990EB4B00CC765C /* CollectionSafeSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09E08C582990EB3800CC765C /* CollectionSafeSpec.swift */; };
09E08C5C2990F8B600CC765C /* QuestionRangePickerView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09E08C5B2990F8B600CC765C /* QuestionRangePickerView.swift */; };
09E08C45298B7DD500CC765C /* QuestionMultiChoiceView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09E08C44298B7DD500CC765C /* QuestionMultiChoiceView.swift */; };
09E08C47298B89F400CC765C /* QuestionMultiFormView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09E08C46298B89F400CC765C /* QuestionMultiFormView.swift */; };
09E6ABF32951D105007F1EE3 /* KIF+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09E6ABF12951D103007F1EE3 /* KIF+Swift.swift */; };
09E6ABFD2951D32F007F1EE3 /* ViewId.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09636B1428D8148C00A5CB97 /* ViewId.swift */; };
09E6ABFE2951D333007F1EE3 /* ViewId+General.swift in Sources */ = {isa = PBXBuildFile; fileRef = 09636B2F28D8267D00A5CB97 /* ViewId+General.swift */; };
Expand Down Expand Up @@ -329,6 +330,7 @@
09E08C582990EB3800CC765C /* CollectionSafeSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CollectionSafeSpec.swift; sourceTree = "<group>"; };
09E08C5B2990F8B600CC765C /* QuestionRangePickerView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = QuestionRangePickerView.swift; sourceTree = "<group>"; };
09E08C44298B7DD500CC765C /* QuestionMultiChoiceView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestionMultiChoiceView.swift; sourceTree = "<group>"; };
09E08C46298B89F400CC765C /* QuestionMultiFormView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuestionMultiFormView.swift; sourceTree = "<group>"; };
09E6ABE42951CF3E007F1EE3 /* SurveyKIFUITests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SurveyKIFUITests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
09E6ABF12951D103007F1EE3 /* KIF+Swift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "KIF+Swift.swift"; sourceTree = "<group>"; };
09E6AC0B2951D5DD007F1EE3 /* AccountSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AccountSpec.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -916,6 +918,7 @@
09E08C4A298CB0BD00CC765C /* QuestionEmojiView.swift */,
09E08C5B2990F8B600CC765C /* QuestionRangePickerView.swift */,
09E08C44298B7DD500CC765C /* QuestionMultiChoiceView.swift */,
09E08C46298B89F400CC765C /* QuestionMultiFormView.swift */,
);
path = SurveyQuestion;
sourceTree = "<group>";
Expand Down Expand Up @@ -1921,6 +1924,7 @@
09CE771328E1A94600EAA9EE /* ResetPasswordView.swift in Sources */,
09FE26CD294B1EE3005A7F85 /* SurveySelectionView+DataSource.swift in Sources */,
09D09DCA29682810009F88AF /* Constants+Animation.swift in Sources */,
09E08C47298B89F400CC765C /* QuestionMultiFormView.swift in Sources */,
09636B3028D8267D00A5CB97 /* ViewId+General.swift in Sources */,
09636B0228D4876100A5CB97 /* PrimaryButton.swift in Sources */,
09CE770C28E191B400EAA9EE /* AppCoordinator.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// QuestionMultiFormView.swift
// Survey
//
// Created by Bliss on 2/2/23.
// Copyright © 2023 Nimble. All rights reserved.
//

import SwiftUI

struct QuestionMultiFormView: View {

struct MultiFormAnswer {

let question: Answer
var input: String = ""
}

@State var multiFormAnswers = [MultiFormAnswer]()

var body: some View {
VStack(spacing: .lineSpacing) {
ForEach(
Array(multiFormAnswers.enumerated()),
id: \.element.question.id
) { index, answer in
TextField(
answer.question.text,
text: $multiFormAnswers[index].input
)
.primaryTextField()
}
}
}

init(answers: [Answer]) {
_multiFormAnswers = .init(
initialValue: answers.map {
MultiFormAnswer(question: $0)
}
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct SurveyQuestionView: View {
)
case .choice:
QuestionMultiChoiceView(options: question.answers)
case .textfield:
QuestionMultiFormView(answers: question.answers)
default:
QuestionPickerView(options: [])
}
Expand Down

0 comments on commit 80cfc71

Please sign in to comment.