Skip to content

Validating a picker #14

@TiPunch69

Description

@TiPunch69

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions