File tree Expand file tree Collapse file tree 4 files changed +26
-6
lines changed
routes/tests/datetime-local Expand file tree Collapse file tree 4 files changed +26
-6
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010### Fixed
1111
1212- When multiple forms exists with the same id, the warning is now displayed on ` superForm ` instantiation, not just when new form data is received.
13- - Fixed client-side validation for ` Date ` schema fields.
13+ - Fixed client-side validation for ` Date ` schema fields. ([ #232 ] ( https://github.com/ciscoheat/sveltekit-superforms/issues/232 ) )
14+ - ` numberProxy ` and ` intProxy ` now works with the ` empty ` option. ([ #232 ] ( https://github.com/ciscoheat/sveltekit-superforms/issues/232 ) )
1415
1516## [ 1.3.0] - 2023-07-14
1617
Original file line number Diff line number Diff line change @@ -133,12 +133,17 @@ function _stringProxy<
133133 options : DefaultOptions
134134) : Writable < string > {
135135 function toValue ( val : unknown ) {
136- if ( typeof val !== 'string' )
137- throw new SuperFormError ( 'stringProxy received a non-string value.' ) ;
138-
139136 if ( ! val && options . empty !== undefined )
140137 return options . empty === 'null' ? null : undefined ;
141138
139+ if ( typeof val === 'number' ) {
140+ val = val . toString ( ) ;
141+ }
142+
143+ if ( typeof val !== 'string' ) {
144+ throw new SuperFormError ( 'stringProxy received a non-string value.' ) ;
145+ }
146+
142147 if ( type == 'string' ) return val ;
143148 else if ( type == 'boolean' ) return ! ! val ;
144149 else if ( type == 'date' ) return new Date ( val ) ;
Original file line number Diff line number Diff line change 11<script lang =" ts" >
2- import { dateProxy , superForm , superValidateSync } from ' $lib/client' ;
2+ import {
3+ dateProxy ,
4+ intProxy ,
5+ superForm ,
6+ superValidateSync
7+ } from ' $lib/client' ;
38 import SuperDebug from ' $lib/client/SuperDebug.svelte' ;
49 import { schema } from ' ./schema' ;
510
2429 format: ' datetime-local' ,
2530 empty: ' undefined'
2631 });
32+
33+ const num = intProxy (form , ' number' , {
34+ empty: ' undefined'
35+ });
2736 </script >
2837
29- <SuperDebug data ={{ $form , $errors , $ tainted }} />
38+ <SuperDebug data ={{ $form , $tainted }} />
3039
3140<form method =" POST" use:enhance >
41+ <label >
42+ Number: <input name ="number" type ="number" bind:value ={$num } />
43+ {#if $errors .number }<span class ="invalid" >{$errors .number }</span >{/if }
44+ </label >
3245 <label >
3346 Name: <input name ="date" type ="datetime-local" bind:value ={$date } />
3447 {#if $errors .date }<span class ="invalid" >{$errors .date }</span >{/if }
Original file line number Diff line number Diff line change 11import { z } from 'zod' ;
22
33export const schema = z . object ( {
4+ number : z . number ( ) . optional ( ) ,
45 date : z
56 . date ( )
67 . min ( new Date ( '2021-01-01' ) )
You can’t perform that action at this time.
0 commit comments