@@ -1363,3 +1363,81 @@ describe("createForm — re-render resilience", () => {
13631363 cleanup ( el ) ;
13641364 } ) ;
13651365} ) ;
1366+
1367+ describe ( "createForm — error clearing on fix" , ( ) => {
1368+ it ( "clears errors on change after failed submission" , ( ) => {
1369+ const el = makeForm ( basicHtml ) ;
1370+ const form = createForm ( { el, schema : basicSchema , onSubmit : ( ) => { } } ) ;
1371+ const unmount = form . mount ( ) ;
1372+
1373+ setField ( el , "email" , "bad" ) ;
1374+ submit ( el ) ;
1375+ expect ( Object . keys ( form . errors ( ) ) . length ) . toBeGreaterThan ( 0 ) ;
1376+
1377+ const input = setField ( el , "email" , "ada@example.com" ) ;
1378+ setField ( el , "name" , "Ada" ) ;
1379+ dispatch ( input , "change" ) ;
1380+
1381+ expect ( form . errors ( ) ) . toEqual ( { } ) ;
1382+ unmount ( ) ;
1383+ cleanup ( el ) ;
1384+ } ) ;
1385+
1386+ it ( "clears errors on input keystroke after failed submission" , ( ) => {
1387+ const el = makeForm ( basicHtml ) ;
1388+ const form = createForm ( { el, schema : basicSchema , onSubmit : ( ) => { } } ) ;
1389+ const unmount = form . mount ( ) ;
1390+
1391+ setField ( el , "email" , "bad" ) ;
1392+ submit ( el ) ;
1393+ expect ( Object . keys ( form . errors ( ) ) . length ) . toBeGreaterThan ( 0 ) ;
1394+
1395+ const input = setField ( el , "email" , "ada@example.com" ) ;
1396+ setField ( el , "name" , "Ada" ) ;
1397+ dispatch ( input , "input" ) ;
1398+
1399+ expect ( form . errors ( ) ) . toEqual ( { } ) ;
1400+ unmount ( ) ;
1401+ cleanup ( el ) ;
1402+ } ) ;
1403+
1404+ it ( "does not revalidate on change when there are no errors (validateOn: submit)" , ( ) => {
1405+ const el = makeForm ( basicHtml ) ;
1406+ const form = createForm ( {
1407+ el,
1408+ schema : basicSchema ,
1409+ onSubmit : ( ) => { } ,
1410+ validateOn : "submit" ,
1411+ } ) ;
1412+ const unmount = form . mount ( ) ;
1413+
1414+ // no prior submission — errors are empty
1415+ const input = setField ( el , "email" , "bad" ) ;
1416+ dispatch ( input , "change" ) ;
1417+
1418+ // should stay empty — no proactive validation when clean
1419+ expect ( form . errors ( ) ) . toEqual ( { } ) ;
1420+ unmount ( ) ;
1421+ cleanup ( el ) ;
1422+ } ) ;
1423+
1424+ it ( "does not revalidate on input when there are no errors (validateOn: submit)" , ( ) => {
1425+ const el = makeForm ( basicHtml ) ;
1426+ const form = createForm ( {
1427+ el,
1428+ schema : basicSchema ,
1429+ onSubmit : ( ) => { } ,
1430+ validateOn : "submit" ,
1431+ } ) ;
1432+ const unmount = form . mount ( ) ;
1433+
1434+ // no prior submission — errors are empty
1435+ const input = setField ( el , "email" , "bad" ) ;
1436+ dispatch ( input , "input" ) ;
1437+
1438+ // should stay empty — no proactive validation when clean
1439+ expect ( form . errors ( ) ) . toEqual ( { } ) ;
1440+ unmount ( ) ;
1441+ cleanup ( el ) ;
1442+ } ) ;
1443+ } ) ;
0 commit comments