SwiftUIFormValidator icon indicating copy to clipboard operation
SwiftUIFormValidator copied to clipboard

Validating a picker

Open TiPunch69 opened this issue 1 year ago • 0 comments

Hi! I am trying to validate a picker and am a little stuck. I use the following inside the form

    @FormField(inlineValidator: { value in
        guard value < 0 || value > 1 else { return "Error" }
        return nil
    })
    @Published var percent: Float = 0
    lazy var percentValidation = _percent.validation(manager: manager, disableValidation: {
        self.amount != 0
    })

and the picker is defined as follows:

 Picker("", selection: self.$value) {
        ForEach(percentages, id: \.self) {
            Text($0, format: .percent).tag($0)
        }
    }
 .validate(validationContainer)

The problem is the Published inside the Formfield property wrapper. Without it the picker does not get updated and with it, I cannot use the validation, as the wrappedValues do not match.

TiPunch69 avatar Oct 09 '23 19:10 TiPunch69