Skip to content

Commit dc4ab30

Browse files
committed
Fixed issue #518: Textarea and select value isn't preserved when going back/forward
1 parent c70ffe2 commit dc4ab30

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

jquery.pjax.js

+14
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,20 @@ function uniqueId() {
556556
}
557557

558558
function cloneContents(container) {
559+
// Preserve textarea values
560+
var textarea = findAll(container, "textarea")
561+
textarea.text(function(i, text){return textarea[i].value})
562+
563+
// Preserve select values
564+
findAll(container, "select").each(function(i, elem){
565+
elem = $(elem);
566+
var values = $(elem).val();
567+
elem.find('option[selected]').attr('selected', false);
568+
elem.find('option').filter(function(){
569+
return ($.inArray(this.value, values) !== -1);
570+
}).attr('selected', true);
571+
})
572+
559573
var cloned = container.clone()
560574
// Unmark script tags as already being eval'd so they can get executed again
561575
// when restored from cache. HAXX: Uses jQuery internal method.

0 commit comments

Comments
 (0)