Skip to content

Typing within the TextField does not persist text changes. #1

Description

@mintuz

Hello, hope you are well. I think I might have discovered a bug and thought I'd get your thoughts on it.

When I capture text from the camera, my @Bindings are updated successfully. However If I type within the same fields and click another element such as a button, the @Bindings are reverted back into their previous state.

I have the following code

struct ElectronicCategoryView: View {
    @Binding var modelNumber: String
    @Binding var serialNumber: String
    
    var body: some View {
        Group {
            ScanTextField("Model Number", text: $modelNumber)
            ScanTextField("Serial Number", text: $serialNumber)
        }
    }
}

The @bindings are bound to a viewModel @published property.

I thought it would be as simple as adding the following code to the ScanTextField but it doesn't seem to work, presumably it's because it's not resigningFirstResponder Have you got any additional thoughts?

public func textFieldDidEndEditing(_ textField: UITextField) {
    parent.text = textField.text ?? ""
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions