File tree Expand file tree Collapse file tree 6 files changed +73
-3
lines changed Expand file tree Collapse file tree 6 files changed +73
-3
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2121
2222### Fixed
2323
24+ - Updating the same variable to the same value prevented the [ onChange] ( https://superforms.rocks/concepts/events#onchange ) event from being triggered.
2425- Factorized [ SuperDebug] ( https://superforms.rocks/super-debug ) clipboard script
2526
2627## [ 2.18.1] - 2024-09-13
Original file line number Diff line number Diff line change @@ -1282,9 +1282,9 @@ export function superForm<
12821282 return currentlyTainted ;
12831283 } ) ;
12841284 }
1285- }
12861285
1287- NextChange_setHtmlEvent ( { paths } ) ;
1286+ NextChange_setHtmlEvent ( { paths } ) ;
1287+ }
12881288 }
12891289
12901290 /**
Original file line number Diff line number Diff line change 6464 ' simple-tainted' ,
6565 ' validity-objects' ,
6666 ' issue-466' ,
67- ' spa-error'
67+ ' spa-error' ,
68+ ' issue-470'
6869 ].sort ();
6970 </script >
7071
Original file line number Diff line number Diff line change 1+ import type { Actions , PageServerLoad } from './$types.js' ;
2+
3+ import { superValidate , message } from '$lib/index.js' ;
4+ import { zod } from '$lib/adapters/zod.js' ;
5+ import { fail } from '@sveltejs/kit' ;
6+ import { schema } from './schema.js' ;
7+
8+ export const load : PageServerLoad = async ( ) => {
9+ return { form : await superValidate ( zod ( schema ) ) } ;
10+ } ;
11+
12+ export const actions : Actions = {
13+ default : async ( { request } ) => {
14+ const form = await superValidate ( request , zod ( schema ) ) ;
15+ console . log ( form ) ;
16+
17+ if ( ! form . valid ) return fail ( 400 , { form } ) ;
18+
19+ return message ( form , 'Form posted successfully!' ) ;
20+ }
21+ } ;
Original file line number Diff line number Diff line change 1+ <script lang =" ts" >
2+ import { superForm } from ' $lib/index.js' ;
3+ import SuperDebug from ' $lib/index.js' ;
4+
5+ export let data;
6+
7+ let changeEvent: unknown | undefined = undefined ;
8+ const { form } = superForm (data .form , {
9+ onChange : (e ) => {
10+ changeEvent = e ;
11+ }
12+ });
13+
14+ function setNumberTwice() {
15+ const value = Math .random ();
16+ $form .value = value ;
17+ $form .value = value ;
18+ }
19+ function setNumberOnce() {
20+ const value = Math .random ();
21+ $form .value = value ;
22+ }
23+ </script >
24+
25+ <SuperDebug data ={$form } />
26+
27+ <h3 >Superforms testing ground - Zod</h3 >
28+
29+ <p >
30+ Bug: If the same value is written twice, no change event is fired If first button is clicked, no
31+ change event is fired (however the value is updated). If the second button is clicked a change
32+ event is fired
33+ </p >
34+
35+ <p >
36+ Change event was:
37+ <code >{JSON .stringify (changeEvent )}</code >
38+ </p >
39+
40+ <button on:click ={setNumberTwice }>Click me to set the same value twice</button >
41+ <button on:click ={setNumberOnce }>Click me to set a value once</button >
42+ <button on:click ={() => (changeEvent = undefined )}>Clear event</button >
Original file line number Diff line number Diff line change 1+ import { z } from 'zod' ;
2+
3+ export const schema = z . object ( {
4+ value : z . number ( ) . nullable ( )
5+ } ) ;
You can’t perform that action at this time.
0 commit comments