dyoo/whalesong

select forms always return the first value regardless of form content

Closed this issue · 3 comments

dyoo commented

The following program shows that something funny is happening. Reported by jvjulien:

#lang planet dyoo/whalesong
(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->dom '(div
                          (h1 "test")
                          (select (@ (id "my-select"))
                                  (option (@ (value "red")) "Red")
                                  (option (@ (value "green")) "Green")
                                  (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 "nothing yet"
          (initial-view bound-view)
          (to-draw draw))
dyoo commented

Bug isolated. For some reason, JQuery clone() does not properly clone the select dom node and does not properly save its value. This looks like a bug in JQuery! ... Actually, this is controlled by the DOM model. The DOM model itself does not properly preserve select's state when doing a cloneNode. Nuts. Trying for a workaround...

dyoo commented

If I change domToArrayTreeCursor to do additional hacking on select blocks, we might be able to work around this:

       var cloned = $(dom).clone(true);
        var sourceSelects = $(dom).find("select");
        var destSelects = cloned.find("select");
        var i;
        for (i = 0; i < sourceSelects.length; ++i) {
            $(destSelects[i]).val($(sourceSelects[i]).val());
        }
        return TreeCursor.adaptTreeCursor(domNodeToArrayTree(cloned.get(0)),
                                          domOpenF,
                                          domCloseF,
                                          domAtomicF);
dyoo commented

will be fixed by 8397c4b