android_catalogue1-6 Exercise 2: Live Trimming and Live Year Error =================================================================== 1. Trim leading spaces as the user types: change onTitleChange in FormViewModel. fun onTitleChange(v: String) = _state.update { it.copy(title = v.trimStart()) } It belongs in the view model, because the view model owns the text; the composable just displays whatever state.title is. (Trailing spaces must NOT be trimmed live: the user could never type a space between two words.) save() still calls trim() as a final safety net. 2. Year error immediately: errors are shown when `state.showErrors && state.yearError`. To show it as soon as the user types an out-of-range year, change the condition in FormContent for the year field to isError = state.yearError (and the same for supportingText). The yearError property already returns false for an empty box and true for a non-empty value outside 1000..(this year + 1), so no view-model change is needed. Note the side effect: while the user types "2", "20", "202" the value is out of range, so the error flashes until the fourth digit arrives. A friendlier rule shows the error only once length == 4: val yearError get() = yearText.isNotEmpty() && (yearText.length < 4 || yearText.toInt() !in 1000..max) and show it live only when yearText.length == 4, or after Save. The choice between "while typing" and "after Save" is a UX decision; the code change is one condition.