@@ -88,7 +88,7 @@ type inputsModel struct {
8888}
8989
9090func (m inputsModel ) Init () tea.Cmd {
91- return textinput .Blink
91+ return tea . Batch ( textinput .Blink , spinner . Tick )
9292}
9393
9494func (m inputsModel ) Update (msg tea.Msg ) (tea.Model , tea.Cmd ) {
@@ -145,13 +145,6 @@ func (m inputsModel) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
145145 m .inputs [i ].input .TextStyle = inputsTextNormalStyle
146146 }
147147
148- if m .focusIndex < len (m .inputs ) && m .inputs [m .focusIndex ].checker != nil {
149- m .err = m .inputs [m .focusIndex ].checker (m .inputs [m .focusIndex ].input .Value ())
150- cmds = append (cmds , spinner .Tick )
151- } else {
152- m .err = nil
153- }
154-
155148 return m , tea .Batch (cmds ... )
156149 }
157150 case string :
@@ -196,12 +189,19 @@ func (m inputsModel) View() string {
196189 button = inputsButtonStyle .Render ("➜ Submit" )
197190 }
198191
199- if m .err != nil {
200- b .WriteString (inputsButtonBlockStyle .Render (button + inputsErrLayout .Render (m .errSpinner .View ()+ " " + inputsErrStyle .Render (m .err .Error ()))))
201- } else {
202- b .WriteString (inputsButtonBlockStyle .Render (button ))
192+ // check input value
193+ for _ , iwc := range m .inputs {
194+ if iwc .checker != nil {
195+ m .err = iwc .checker (iwc .input .Value ())
196+ if m .err != nil {
197+ button += inputsErrLayout .Render (m .errSpinner .View () + " " + inputsErrStyle .Render (m .err .Error ()))
198+ break
199+ }
200+ }
203201 }
204202
203+ b .WriteString (inputsButtonBlockStyle .Render (button ))
204+
205205 title := inputsTitleBarStyle .Render (inputsTitleStyle .Render (m .title ))
206206 inputs := inputsBlockStyle .Render (b .String ())
207207
0 commit comments