Добавление и исправление комментариев, начало добавление валидации, сообщение прокрути viewport на форме

This commit is contained in:
XeRo 2026-01-20 17:40:21 +05:00
parent c7ff7662ba
commit e37cabadcc
14 changed files with 371 additions and 297 deletions

View file

@ -14,9 +14,13 @@ type InputModel struct {
input textinput.Model
}
type FieldValidator func(value any) error
// NewInputModel создает новую модель поля ввода данных
func NewInputModel(label, value, description string) *InputModel {
func NewInputModel(label, value, description string, validator textinput.ValidateFunc) *InputModel {
t := textinput.New()
t.Validate = validator
t.SetValue(value)
t.Cursor.SetMode(cursor.CursorBlink)
return &InputModel{
@ -39,7 +43,9 @@ func (m *InputModel) Update(msg tea.Msg) (FieldModel, tea.Cmd) {
func (m *InputModel) View() string {
res := fmt.Sprintf("%s: %v", m.label, m.input.View())
if m.description != "" {
if m.input.Err != nil {
res += fmt.Sprintf("\nОшибка валидации: %s", m.input.Err)
} else if m.description != "" {
res += fmt.Sprintf("\n%s", m.description)
}
return res