handle on input text change for error handling
This commit is contained in:
parent
ff254f674a
commit
abaf3ddf89
|
@ -1,6 +1,7 @@
|
|||
// Copyright © 2023 Rangeproof Pty Ltd. All rights reserved.
|
||||
|
||||
import SwiftUI
|
||||
import Combine
|
||||
|
||||
public struct SessionTextField: View {
|
||||
@Binding var text: String
|
||||
|
@ -31,14 +32,14 @@ public struct SessionTextField: View {
|
|||
|
||||
SwiftUI.TextField(
|
||||
"",
|
||||
text: $text
|
||||
text: $text.onChange{ value in
|
||||
if error?.isEmpty == false && text != value {
|
||||
error = nil
|
||||
}
|
||||
}
|
||||
)
|
||||
.font(.system(size: Values.mediumFontSize))
|
||||
.foregroundColor(themeColor: (error?.isEmpty == false) ? .danger : .textPrimary)
|
||||
.onReceive(text.publisher, perform: { _ in
|
||||
error = nil
|
||||
})
|
||||
|
||||
}
|
||||
.padding(.horizontal, Values.largeSpacing)
|
||||
.frame(
|
||||
|
|
|
@ -85,3 +85,15 @@ extension View {
|
|||
)
|
||||
}
|
||||
}
|
||||
|
||||
extension Binding {
|
||||
public func onChange(_ handler: @escaping (Value) -> Void) -> Binding<Value> {
|
||||
Binding(
|
||||
get: { self.wrappedValue },
|
||||
set: { newValue in
|
||||
handler(newValue)
|
||||
self.wrappedValue = newValue
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue