ckirkendall / enfocus

DOM manipulation and templating library for ClojureScript inspired by Enlive.
http://ckirkendall.github.com/enfocus-site/
370 stars 41 forks source link

(read-form) on IE8 results in [object]is not ISeqable #93

Closed terjesb closed 10 years ago

terjesb commented 10 years ago

(read-form) works on IE9, but fails on IE8 with [object]is not ISeqable.

(read-form-input) works on both.

Applies to both 2.0.2 and 2.1.0-SNAPSHOT.

ckirkendall commented 10 years ago

@terjesb I have a feeling this is due to the call to (.-elements node) in the code. My guess is IE8 returns some native object that doesn't extend the right protocols. I don't have IE 8 to test this so if I come up with a solution can you test it.

(defn read-form
  "returns a map of the form values tied to name of input fields.
   {:name1 'value1' name2 #{'select1' 'select2'}}"
  []
  (extr-multi-node
   (fn [node]
     (let [inputs (.-elements node)]
       (reduce
        #(if-not (empty? (.-name %2))
           (merge-form-val %1
                           (keyword (.-name %2))
                           ((read-form-input) %2))
           %1)
        {} inputs)))))
ckirkendall commented 10 years ago

oops hit the wrong button and closed this.

terjesb commented 10 years ago

Thanks! It almost looks as if IE8 doesn't have an 'elements'. When I check the debugger, it says that elements is also a DispHTMLFormElement, the same as the form itself. When I do an alert(document.getElementById("myform").elements), it prints [object HTMLFormElement].

skjermbilde 2014-04-29 kl 19 25 56

terjesb commented 10 years ago

Perhaps a solution could be to use goog.dom.forms.getFormDataAsMap and then transform that to a regular (read-form)-compatible map.

ckirkendall commented 10 years ago

It because the form itself in IE8 operates as the array. I think it would be best to just use (range (.-length inputs)) and (.item inputs %2) where %2 is.

(defn read-form
  "returns a map of the form values tied to name of input fields.
   {:name1 'value1' name2 #{'select1' 'select2'}}"
  []
  (extr-multi-node
   (fn [node]
     (let [inputs (.-elements node)]
       (reduce
        #(if-not (empty? (.-name (.item inputs %2)))
           (merge-form-val %1
                           (keyword (.-name (.item inputs %2)))
                           ((read-form-input) (item inputs %2 ))
           %1)
        {} (range (.-length inputs))))))

I don't have IE8 so I will try to patch it tonight and maybe you can test in the morning.

ckirkendall commented 10 years ago

@terjesb I pushed a new snapshot version with the fix. Can you test it out.

terjesb commented 10 years ago

Great, now it works in IE8. Thank you very much.