Skip to content

Commit cdc3347

Browse files
authored
Trigger UI update when server changes a form field value (#1483)
* Trigger UI update when server changes a form field value * Update CHANGELOG
1 parent aba2ed1 commit cdc3347

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
- `liveview-native-core` has been updated to v0.4.0, and is now used for all internal networking
2222

2323
### Fixed
24+
- Views will now update properly when the server changes the value of a form field (#1483)
2425

2526
## [0.3.1] 2024-10-02
2627

Sources/LiveViewNative/Property Wrappers/FormState.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ private class FormStateData<Value: FormValue>: ObservableObject {
276276
// When the element updates from the server, sync the new value into the form.
277277
elementCancellable = element.projectedValue
278278
.receive(on: DispatchQueue.main)
279-
.sink { [weak formModel] _ in
279+
.sink { [weak formModel, weak self] _ in
280280
// ignore server updates if the field is focused.
281281
guard !isFocused.wrappedValue && !isEditing.wrappedValue else { return }
282282
formModel?.setServerValue(
@@ -285,6 +285,7 @@ private class FormStateData<Value: FormValue>: ObservableObject {
285285
?? defaultValue,
286286
forName: elementName
287287
)
288+
self?.objectWillChange.send()
288289
}
289290

290291
// Remove all focus from form fields when the form is submitted.

0 commit comments

Comments
 (0)