diff --git a/racket-webview.rkt b/racket-webview.rkt index 5ae53f8..6f2fe80 100644 --- a/racket-webview.rkt +++ b/racket-webview.rkt @@ -745,7 +745,8 @@ (if (string? html) (let ((r (webview-call-js wv (with-id id el - ("el.innerHTML = '~a'; return true;" (esc-quote html)))))) + ("el.innerHTML = '~a'; +await new Promise(resolve => setTimeout(resolve, 0)); return true;" (esc-quote html)))))) (if r 'oke 'failed)) (webview-set-innerHTML! wv id (xexpr->string html)) ) diff --git a/wv-window.rkt b/wv-window.rkt index 6e210a8..98b471c 100644 --- a/wv-window.rkt +++ b/wv-window.rkt @@ -89,38 +89,46 @@ (type (if (null? type*) #f (car type*)))) (when (eq? elem #f) (when (eq? type #f) - (let ((js-type (webview-call-js wv - (format + (let ((js-type -1)) + (set! js-type (webview-call-js wv + (format (string-append "{ let el = document.getElementById('~a');\n" - " let a = (el === null) ? null : el.getAttribute('type');\n" - " if (a === null) {\n" - " return false;\n" - " } else {\n" - " return a;\n" + " let a = (el === null) ? -1 : el.getAttribute('type');\n" + " if (a == -1) {\n" + " return a;\n" + " else { \n" + " if (a === null) {\n" + " return false;\n" + " } else {\n" + " return a;\n" + " }" " }\n" "}") id)))) (set! type (if (eq? js-type #f) - #f - (string->symbol (string-downcase js-type)))) - ) - ) - (let ((cl (cond - ((eq? type 'text) wv-input/text%) - ((eq? type 'date) wv-input/date%) - ((eq? type 'time) wv-input/time%) - ((eq? type 'datetime-local) wv-input/datetime%) - ((eq? type 'range) wv-input/range%) - ((eq? type 'number) wv-input/number%) - ((eq? type 'checkbox) wv-input/check%) - ((eq? type 'radio) wv-input/radio%) - ((eq? type 'color) wv-input/color%) - (else wv-element%) - ))) - (set! elem (new cl [window this] [element-id id])) - (hash-set! element-hash id elem)) - ) + (if (= js-type -1) + 'unknown + (string->symbol (string-downcase js-type))))) + (let ((cl (cond + ((eq? type 'text) wv-input/text%) + ((eq? type 'date) wv-input/date%) + ((eq? type 'time) wv-input/time%) + ((eq? type 'datetime-local) wv-input/datetime%) + ((eq? type 'range) wv-input/range%) + ((eq? type 'number) wv-input/number%) + ((eq? type 'checkbox) wv-input/check%) + ((eq? type 'radio) wv-input/radio%) + ((eq? type 'color) wv-input/color%) + ((eq? type 'unknown) (begin + (err-webview "Element with id '~a' not found" + id) + wv-element%)) + (else wv-element%) + ))) + (set! elem (new cl [window this] [element-id id])) + (hash-set! element-hash id elem)) + )) elem ) )