Skip to content

Commit

Permalink
back to using numericValue (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
piever authored Mar 29, 2019
1 parent 1f0fbf0 commit b87c8a0
Showing 1 changed file with 3 additions and 30 deletions.
33 changes: 3 additions & 30 deletions src/input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -158,42 +158,15 @@ function input(::WidgetTheme, o; extra_js=js"", extra_obs=[], label=nothing, typ
(o isa AbstractObservable) || (o = Observable(o))
(changes isa AbstractObservable) || (changes = Observable(changes))
data = Pair{String, Any}["changes" => changes, bindto => o]
if isnumeric
bindtoString = bindto*"String"
oString = Observable(string(something(o[], "")))
push!(data, bindtoString => oString)
string_js = js"""
var obs = this.$(WebIO.JSString(bindto));
var obsString = this.$(WebIO.JSString(bindtoString));
obsString.subscribe(function(value) {
var val = parseFloat(value);
if (!isNaN(val)) {
obs(val);
}
})
obs.subscribe(function(value) {
var str = JSON.stringify(value);
if ((str == "0") && (["-0", "-0."].indexOf(obsString()) >= 0))
return;
if (["null", ""].indexOf(str) >= 0)
return;
obsString(str);
})
"""
extra_js = js"""
$string_js
$extra_js
"""
else
bindtoString = bindto
oString = o
if isnumeric && bind == "value"
bind = "numericValue"
end
append!(data, (string(key) => val for (key, val) in extra_obs))
countChanges = js_lambda("this.changes(this.changes()+1)")
attrDict = merge(
attributes,
Dict(:type => typ,
Symbol("data-bind") => "$bind: $bindtoString, valueUpdate: '$valueUpdate', event: {change: $countChanges}"
Symbol("data-bind") => "$bind: $bindto, valueUpdate: '$valueUpdate', event: {change: $countChanges}"
)
)
className = mergeclasses(getclass(:input, wdgtyp), className)
Expand Down

0 comments on commit b87c8a0

Please sign in to comment.