@@ -366,6 +366,51 @@ describe("Core morphing tests", function () {
366366 document . body . removeChild ( parent ) ;
367367 } ) ;
368368
369+ it ( "ignore input value change when ignoreValue is true" , function ( ) {
370+ let parent = make ( "<div><input value='foo'></div>" ) ;
371+ document . body . append ( parent ) ;
372+
373+ let initial = parent . querySelector ( "input" ) ;
374+
375+ // morph
376+ let finalSrc = '<input value="bar">' ;
377+ Idiomorph . morph ( initial , finalSrc , { morphStyle : "outerHTML" } ) ;
378+ initial . outerHTML . should . equal ( '<input value="bar">' ) ;
379+
380+ document . activeElement . should . equal ( document . body ) ;
381+
382+ let finalSrc2 = '<input class="foo" value="doh">' ;
383+ Idiomorph . morph ( initial , finalSrc2 , {
384+ morphStyle : "outerHTML" ,
385+ ignoreValue : true ,
386+ } ) ;
387+ initial . value . should . equal ( "bar" ) ;
388+ initial . classList . value . should . equal ( "foo" ) ;
389+
390+ document . body . removeChild ( parent ) ;
391+ } ) ;
392+
393+ it ( "ignores textarea value when ignoreValue is true" , function ( ) {
394+ let parent = make ( "<div><textarea>foo</textarea></div>" ) ;
395+ document . body . append ( parent ) ;
396+ let initial = parent . querySelector ( "textarea" ) ;
397+
398+ let finalSrc = "<textarea>bar</textarea>" ;
399+ Idiomorph . morph ( initial , finalSrc , { morphStyle : "outerHTML" } ) ;
400+ initial . outerHTML . should . equal ( "<textarea>bar</textarea>" ) ;
401+
402+ document . activeElement . should . equal ( document . body ) ;
403+
404+ let finalSrc2 = '<textarea class="foo">doh</textarea>' ;
405+ Idiomorph . morph ( initial , finalSrc2 , {
406+ morphStyle : "outerHTML" ,
407+ ignoreValue : true ,
408+ } ) ;
409+ initial . outerHTML . should . equal ( '<textarea class="foo">bar</textarea>' ) ;
410+
411+ document . body . removeChild ( parent ) ;
412+ } ) ;
413+
369414 it ( "can morph input value properly because value property is special and doesnt reflect" , function ( ) {
370415 let initial = make ( '<div><input value="foo"></div>' ) ;
371416 let final = make ( '<input value="foo">' ) ;
@@ -419,6 +464,70 @@ describe("Core morphing tests", function () {
419464 document . body . removeChild ( parent ) ;
420465 } ) ;
421466
467+ it ( "morph does not remove input checked with ignoreValue set" , function ( ) {
468+ let parent = make ( '<div><input type="checkbox"></div>' ) ;
469+ document . body . append ( parent ) ;
470+ let initial = parent . querySelector ( "input" ) ;
471+ initial . checked = true ;
472+
473+ let finalSrc = '<input type="checkbox">' ;
474+ Idiomorph . morph ( initial , finalSrc , { morphStyle : "outerHTML" , ignoreValue : true } ) ;
475+ initial . outerHTML . should . equal ( '<input type="checkbox">' ) ;
476+ initial . checked . should . equal ( true ) ;
477+ document . body . removeChild ( parent ) ;
478+ } ) ;
479+
480+ it ( "morph does not reset input checked with ignoreValue set" , function ( ) {
481+ let parent = make ( '<div><input type="checkbox" checked></div>' ) ;
482+ document . body . append ( parent ) ;
483+ let initial = parent . querySelector ( "input" ) ;
484+ initial . checked = false ;
485+
486+ let finalSrc = '<input type="checkbox" checked>' ;
487+ Idiomorph . morph ( initial , finalSrc , { morphStyle : "outerHTML" , ignoreValue : true } ) ;
488+ initial . outerHTML . should . equal ( '<input type="checkbox" checked="">' ) ;
489+ initial . checked . should . equal ( false ) ;
490+ document . body . removeChild ( parent ) ;
491+ } ) ;
492+
493+ it ( "morph does still set input checked when checked attribute added even with ignoreValue set" , function ( ) {
494+ let parent = make ( '<div><input type="checkbox" checked></div>' ) ;
495+ document . body . append ( parent ) ;
496+ let initial = parent . querySelector ( "input" ) ;
497+
498+ let MiddleSrc = '<input type="checkbox">' ;
499+ Idiomorph . morph ( initial , MiddleSrc , { morphStyle : "outerHTML" } ) ;
500+
501+ initial . outerHTML . should . equal ( '<input type="checkbox">' ) ;
502+ initial . checked . should . equal ( false ) ;
503+
504+ let finalSrc = '<input type="checkbox" checked>' ;
505+
506+ Idiomorph . morph ( initial , finalSrc , { morphStyle : "outerHTML" , ignoreValue : true } ) ;
507+ initial . outerHTML . should . equal ( '<input type="checkbox" checked="">' ) ;
508+ initial . checked . should . equal ( true ) ;
509+ document . body . removeChild ( parent ) ;
510+ } ) ;
511+
512+ it ( "morph does still remove input checked when checked attribute removed even with ignoreValue set" , function ( ) {
513+ let parent = make ( '<div><input type="checkbox"></div>' ) ;
514+ document . body . append ( parent ) ;
515+ let initial = parent . querySelector ( "input" ) ;
516+
517+ let MiddleSrc = '<input type="checkbox" checked>' ;
518+ Idiomorph . morph ( initial , MiddleSrc , { morphStyle : "outerHTML" } ) ;
519+
520+ initial . outerHTML . should . equal ( '<input type="checkbox" checked="">' ) ;
521+ initial . checked . should . equal ( true ) ;
522+
523+ let finalSrc = '<input type="checkbox">' ;
524+
525+ Idiomorph . morph ( initial , finalSrc , { morphStyle : "outerHTML" , ignoreValue : true } ) ;
526+ initial . outerHTML . should . equal ( '<input type="checkbox">' ) ;
527+ initial . checked . should . equal ( false ) ;
528+ document . body . removeChild ( parent ) ;
529+ } ) ;
530+
422531 it ( "can morph input checked properly, set checked property to true" , function ( ) {
423532 let parent = make ( '<div><input type="checkbox" checked></div>' ) ;
424533 document . body . append ( parent ) ;
@@ -427,7 +536,7 @@ describe("Core morphing tests", function () {
427536
428537 let finalSrc = '<input type="checkbox" checked>' ;
429538 Idiomorph . morph ( initial , finalSrc , { morphStyle : "outerHTML" } ) ;
430- initial . outerHTML . should . equal ( '<input type="checkbox" checked="true ">' ) ;
539+ initial . outerHTML . should . equal ( '<input type="checkbox" checked="">' ) ;
431540 initial . checked . should . equal ( true ) ;
432541 document . body . removeChild ( parent ) ;
433542 } ) ;
@@ -474,7 +583,7 @@ describe("Core morphing tests", function () {
474583 // is this a problem at all?
475584 parent . innerHTML . should . equal ( `
476585 <select>
477- <option selected="true ">0</option>
586+ <option selected="">0</option>
478587 <option>1</option>
479588 </select>
480589 ` ) ;
@@ -506,7 +615,7 @@ describe("Core morphing tests", function () {
506615 let finalSrc = `
507616 <select>
508617 <option>0</option>
509- <option selected="true ">1</option>
618+ <option selected="">1</option>
510619 </select>
511620 ` ;
512621 Idiomorph . morph ( parent , finalSrc , { morphStyle : "innerHTML" } ) ;
0 commit comments