swiftui forms not appearing inside list

Viewed 2897

I am developing a certain application where it requires a user to fill a form. a form is not a problem actually but problem is when i want more than just one form dynamically. The number of forms (of the same look) depends on a certain number. So i decided to create a model and put the form in the list. That way the number of forms will be equal to nth number. problem is they are not appearing. If i remove the form they appear, if i put a form they do not. Is it that a form is not allowed in the list?

Below is expected results

This is what i want

But when i add the form in the list i get This is what i get

So here's my simple List:

struct UserTab: View {
let seats = ["A4", "B2", "C1", "D3"]
var body: some View {
    List(seats, id: \.self){seat in
        PassengerInfoModel()
    }
}

The PassengerInfoModel is below:

    struct PassengerInfoModel: View {
    @State private var fullName: String = ""
    var body: some View {
        Form{
            Text("Paasenger 1")
            TextField("Full name", text: $fullName)
        }
    }
}

Thanks in advance.

1 Answers

Because the form frame is not determined, you get this result. Try to add some frame to your form and it should be ok

struct PassengerInfoModel: View {
    @State private var fullName: String = ""
    var body: some View {
        Form{
            Text("Paasenger 1")
            TextField("Full name", text: $fullName)
        }.frame(height: 200)
    }
}

In general you should avoid using Form inside Scrollview because both of them has scroll and not working as you want

Related