File tree Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Expand file tree Collapse file tree 3 files changed +21
-2
lines changed Original file line number Diff line number Diff line change @@ -3966,7 +3966,7 @@ var htmx = (function() {
39663966 const formData = new FormData ( )
39673967 for ( const key in obj ) {
39683968 if ( obj . hasOwnProperty ( key ) ) {
3969- if ( typeof obj [ key ] . forEach === 'function' ) {
3969+ if ( obj [ key ] && typeof obj [ key ] . forEach === 'function' ) {
39703970 obj [ key ] . forEach ( function ( v ) { formData . append ( key , v ) } )
39713971 } else if ( typeof obj [ key ] === 'object' && ! ( obj [ key ] instanceof Blob ) ) {
39723972 formData . append ( key , JSON . stringify ( obj [ key ] ) )
@@ -4059,7 +4059,7 @@ var htmx = (function() {
40594059 return false
40604060 }
40614061 target . delete ( name )
4062- if ( typeof value . forEach === 'function' ) {
4062+ if ( value && typeof value . forEach === 'function' ) {
40634063 value . forEach ( function ( v ) { target . append ( name , v ) } )
40644064 } else if ( typeof value === 'object' && ! ( value instanceof Blob ) ) {
40654065 target . append ( name , JSON . stringify ( value ) )
Original file line number Diff line number Diff line change @@ -297,4 +297,15 @@ describe('hx-vals attribute', function() {
297297 }
298298 calledEvent . should . equal ( true )
299299 } )
300+ it ( 'hx-vals works with null values' , function ( ) {
301+ this . server . respondWith ( 'POST' , '/vars' , function ( xhr ) {
302+ var params = getParameters ( xhr )
303+ params . i1 . should . equal ( 'null' )
304+ xhr . respond ( 200 , { } , 'Clicked!' )
305+ } )
306+ var div = make ( "<div hx-post='/vars' hx-vals='{\"i1\": null }'></div>" )
307+ div . click ( )
308+ this . server . respond ( )
309+ div . innerHTML . should . equal ( 'Clicked!' )
310+ } )
300311} )
Original file line number Diff line number Diff line change @@ -280,6 +280,14 @@ describe('Core htmx Parameter Handling', function() {
280280 vals . foo . should . equal ( 'bar' )
281281 } )
282282
283+ it ( 'formdata works with null values' , function ( ) {
284+ var form = make ( '<form hx-post="/test"><input name="foo" value="bar"/></form>' )
285+ var vals = htmx . _ ( 'getInputValues' ) ( form , 'get' ) . values
286+ function updateToNull ( ) { vals . foo = null }
287+ updateToNull . should . not . throw ( )
288+ vals . foo . should . equal ( 'null' )
289+ } )
290+
283291 it ( 'order of parameters follows order of input elements' , function ( ) {
284292 this . server . respondWith ( 'GET' , '/test?foo=bar&bar=foo&foo=bar&foo2=bar2' , function ( xhr ) {
285293 xhr . respond ( 200 , { } , 'Clicked!' )
You can’t perform that action at this time.
0 commit comments