fix for issue 91
This commit is contained in:
parent
995f093baa
commit
8397c4bece
|
@ -2,13 +2,26 @@
|
||||||
|
|
||||||
(require (planet dyoo/whalesong/web-world))
|
(require (planet dyoo/whalesong/web-world))
|
||||||
|
|
||||||
|
(define (draw w v)
|
||||||
|
(define v2 (view-focus v "fill-me-in"))
|
||||||
|
(update-view-text v2 w))
|
||||||
|
|
||||||
(define view (xexp->view '(select (@ (id "my-select"))
|
(define view (xexp->dom '(div
|
||||||
|
(h1 "test")
|
||||||
|
(select (@ (id "my-select"))
|
||||||
(option (@ (value "red")) "Red")
|
(option (@ (value "red")) "Red")
|
||||||
(option (@ (value "green")) "Green")
|
(option (@ (value "green")) "Green")
|
||||||
(option (@ (value "blue")) "Blue"))))
|
(option (@ (value "blue")) "Blue"))
|
||||||
|
(p
|
||||||
|
"I see: "
|
||||||
|
(span (@ (id "fill-me-in")))))))
|
||||||
|
|
||||||
|
(define (when-select-changed w v)
|
||||||
|
(printf "I see: ~s\n" (view-form-value (view-focus v "my-select")))
|
||||||
|
(view-form-value (view-focus v "my-select")))
|
||||||
|
|
||||||
|
(define bound-view (view-bind-many view ["my-select" "change" when-select-changed]))
|
||||||
|
|
||||||
(big-bang 'undefined
|
(big-bang "nothing yet"
|
||||||
(initial-view view))
|
(initial-view bound-view)
|
||||||
|
(to-draw draw))
|
|
@ -67,6 +67,23 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// Deeply clones a dom node.
|
||||||
|
//
|
||||||
|
// Note: we have to do a small hack to propagate the values of
|
||||||
|
// select forms. See: https://github.com/dyoo/whalesong/issues/91
|
||||||
|
var deepClone = function(dom) {
|
||||||
|
var theClone = $(dom).clone(true).get(0);
|
||||||
|
var sourceSelects = $(dom).find("select");
|
||||||
|
var destSelects = $(theClone).find("select");
|
||||||
|
var i;
|
||||||
|
for (i = 0; i < sourceSelects.length; ++i) {
|
||||||
|
$(destSelects[i]).val($(sourceSelects[i]).val());
|
||||||
|
}
|
||||||
|
return theClone;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// CPS'd version of for-each, used on JavaScript arrays.
|
// CPS'd version of for-each, used on JavaScript arrays.
|
||||||
//
|
//
|
||||||
// Take care: elts can't be too large or else we'll stack
|
// Take care: elts can't be too large or else we'll stack
|
||||||
|
@ -124,7 +141,7 @@
|
||||||
function(tree) {
|
function(tree) {
|
||||||
return tree[0].nodeType !== 1;
|
return tree[0].nodeType !== 1;
|
||||||
};
|
};
|
||||||
return TreeCursor.adaptTreeCursor(domNodeToArrayTree($(dom).clone(true).get(0)),
|
return TreeCursor.adaptTreeCursor(domNodeToArrayTree(deepClone(dom)),
|
||||||
domOpenF,
|
domOpenF,
|
||||||
domCloseF,
|
domCloseF,
|
||||||
domAtomicF);
|
domAtomicF);
|
||||||
|
@ -526,7 +543,7 @@
|
||||||
},
|
},
|
||||||
function(eventHandlers) { return eventHandlers; },
|
function(eventHandlers) { return eventHandlers; },
|
||||||
function(view) {
|
function(view) {
|
||||||
var clone = $(domNode).clone(true);
|
var clone = deepClone(domNode);
|
||||||
clone.appendTo($(view.focus));
|
clone.appendTo($(view.focus));
|
||||||
view.focus = clone.get(0);
|
view.focus = clone.get(0);
|
||||||
}
|
}
|
||||||
|
@ -540,7 +557,7 @@
|
||||||
},
|
},
|
||||||
function(eventHandlers) { return eventHandlers; },
|
function(eventHandlers) { return eventHandlers; },
|
||||||
function(view) {
|
function(view) {
|
||||||
var clone = $(domNode).clone(true);
|
var clone = deepClone(domNode);
|
||||||
clone.insertAfter($(view.focus));
|
clone.insertAfter($(view.focus));
|
||||||
view.focus = clone.get(0);
|
view.focus = clone.get(0);
|
||||||
}
|
}
|
||||||
|
@ -554,7 +571,7 @@
|
||||||
},
|
},
|
||||||
function(eventHandlers) { return eventHandlers; },
|
function(eventHandlers) { return eventHandlers; },
|
||||||
function(view) {
|
function(view) {
|
||||||
var clone = $(domNode).clone(true);
|
var clone = deepClone(domNode);
|
||||||
clone.insertBefore($(view.focus));
|
clone.insertBefore($(view.focus));
|
||||||
view.focus = clone.get(0);
|
view.focus = clone.get(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user