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
21
21
22
22
### Fixed
23
23
24
+ - Updating the same variable to the same value prevented the [ onChange] ( https://superforms.rocks/concepts/events#onchange ) event from being triggered.
24
25
- Factorized [ SuperDebug] ( https://superforms.rocks/super-debug ) clipboard script
25
26
26
27
## [ 2.18.1] - 2024-09-13
Original file line number Diff line number Diff line change @@ -1282,9 +1282,9 @@ export function superForm<
1282
1282
return currentlyTainted ;
1283
1283
} ) ;
1284
1284
}
1285
- }
1286
1285
1287
- NextChange_setHtmlEvent ( { paths } ) ;
1286
+ NextChange_setHtmlEvent ( { paths } ) ;
1287
+ }
1288
1288
}
1289
1289
1290
1290
/**
Original file line number Diff line number Diff line change 64
64
' simple-tainted' ,
65
65
' validity-objects' ,
66
66
' issue-466' ,
67
- ' spa-error'
67
+ ' spa-error' ,
68
+ ' issue-470'
68
69
].sort ();
69
70
</script >
70
71
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