Closed terjesb closed 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)))))
oops hit the wrong button and closed this.
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].
Perhaps a solution could be to use goog.dom.forms.getFormDataAsMap and then transform that to a regular (read-form)-compatible map.
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.
@terjesb I pushed a new snapshot version with the fix. Can you test it out.
Great, now it works in IE8. Thank you very much.
(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.