@@ -1099,4 +1099,161 @@ if ($.support.pjax) {
10991099 equal ( frame . location . search , "" )
11001100 } )
11011101 } )
1102+
1103+ asyncTest ( "preserves input value when going back and forth" , 1 , function ( ) {
1104+ var count = 0
1105+ var frame = this . frame
1106+
1107+ frame . $ . pjax ( { url : "form.html" , container : "#main" } )
1108+
1109+ frame . $ ( "#main" ) . on ( "pjax:end" , function ( ) {
1110+ count ++
1111+ var field = frame . $ ( "input[type=text]" )
1112+
1113+ if ( count == 1 ) {
1114+ // Form
1115+ field . val ( "changed" )
1116+ frame . history . back ( )
1117+ } else if ( count == 2 ) {
1118+ // Hello
1119+ frame . history . forward ( )
1120+ } else if ( count == 3 ) {
1121+ // Form
1122+ equal ( field . val ( ) , "changed" , "Field value is preserved" )
1123+ start ( )
1124+ }
1125+ } )
1126+ } )
1127+
1128+ asyncTest ( "preserves textarea value when going back and forth" , 1 , function ( ) {
1129+ var count = 0
1130+ var frame = this . frame
1131+
1132+ frame . $ . pjax ( { url : "form.html" , container : "#main" } )
1133+
1134+ frame . $ ( "#main" ) . on ( "pjax:end" , function ( ) {
1135+ count ++
1136+ var field = frame . $ ( "textarea" )
1137+
1138+ if ( count == 1 ) {
1139+ // Form
1140+ field . val ( "changed" )
1141+ frame . history . back ( )
1142+ } else if ( count == 2 ) {
1143+ // Hello
1144+ frame . history . forward ( )
1145+ } else if ( count == 3 ) {
1146+ // Form
1147+ equal ( field . val ( ) , "changed" , "Field value is preserved" )
1148+ start ( )
1149+ }
1150+ } )
1151+ } )
1152+
1153+ asyncTest ( "preserves checkbox value when going back and forth" , 1 , function ( ) {
1154+ var count = 0
1155+ var frame = this . frame
1156+
1157+ frame . $ . pjax ( { url : "form.html" , container : "#main" } )
1158+
1159+ frame . $ ( "#main" ) . on ( "pjax:end" , function ( ) {
1160+ count ++
1161+ var field = frame . $ ( "input[type=checkbox]" )
1162+
1163+ if ( count == 1 ) {
1164+ // Form
1165+ field . prop ( "checked" , true )
1166+ frame . history . back ( )
1167+ } else if ( count == 2 ) {
1168+ // Hello
1169+ frame . history . forward ( )
1170+ } else if ( count == 3 ) {
1171+ // Form
1172+ ok ( field . prop ( "checked" ) , "Field value is preserved" )
1173+ start ( )
1174+ }
1175+ } )
1176+ } )
1177+
1178+ asyncTest ( "preserves checkbox value when going back and forth" , 1 , function ( ) {
1179+ var count = 0
1180+ var frame = this . frame
1181+
1182+ frame . $ . pjax ( { url : "form.html" , container : "#main" } )
1183+
1184+ frame . $ ( "#main" ) . on ( "pjax:end" , function ( ) {
1185+ count ++
1186+ var field = frame . $ ( "input[type=radio]" )
1187+
1188+ if ( count == 1 ) {
1189+ // Form
1190+ field . prop ( "checked" , true )
1191+ frame . history . back ( )
1192+ } else if ( count == 2 ) {
1193+ // Hello
1194+ frame . history . forward ( )
1195+ } else if ( count == 3 ) {
1196+ // Form
1197+ ok ( field . prop ( "checked" ) , "Field value is preserved" )
1198+ start ( )
1199+ }
1200+ } )
1201+ } )
1202+
1203+ asyncTest ( "preserves select value when going back and forth" , 1 , function ( ) {
1204+ var count = 0
1205+ var frame = this . frame
1206+
1207+ frame . $ . pjax ( { url : "form.html" , container : "#main" } )
1208+
1209+ frame . $ ( "#main" ) . on ( "pjax:end" , function ( ) {
1210+ count ++
1211+ var option = frame . $ ( "select option:last" )
1212+
1213+ if ( count == 1 ) {
1214+ // Form
1215+ option . prop ( "selected" , true )
1216+
1217+ frame . history . back ( )
1218+ } else if ( count == 2 ) {
1219+ // Hello
1220+ frame . history . forward ( )
1221+ } else if ( count == 3 ) {
1222+ // Form
1223+ //var option = frame.$("select option:last")
1224+ equal ( option . prop ( "selected" ) , true , "Field value is preserved" )
1225+ start ( )
1226+ }
1227+ } )
1228+ } )
1229+
1230+ asyncTest ( "preserves multiple select value when going back and forth" , 3 , function ( ) {
1231+ var count = 0
1232+ var frame = this . frame
1233+
1234+ frame . $ . pjax ( { url : "form.html" , container : "#main" } )
1235+
1236+ frame . $ ( "#main" ) . on ( "pjax:end" , function ( ) {
1237+ count ++
1238+ var field = frame . $ ( "select" ) . prop ( "multiple" , true )
1239+ var options = field . find ( "option" )
1240+
1241+ if ( count == 1 ) {
1242+ // Form
1243+ options . prop ( "selected" , true )
1244+
1245+ frame . history . back ( )
1246+ } else if ( count == 2 ) {
1247+ // Hello
1248+ frame . history . forward ( )
1249+ } else if ( count == 3 ) {
1250+ // Form
1251+ options . each ( function ( ) {
1252+ equal ( $ ( this ) . prop ( "selected" ) , true , "Field value is preserved" )
1253+ } )
1254+ start ( )
1255+ }
1256+ } )
1257+ } )
1258+
11021259}
0 commit comments