JuliaGizmos / Escher.jl

Composable Web UIs in Julia
https://juliagizmos.github.io/Escher.jl
Other
337 stars 63 forks source link

using the dict in form.jl #154

Closed xiuliren closed 8 years ago

xiuliren commented 8 years ago

Using form.jl in example, I can print the string(dict), but can not use the dict with key!

I used dict[:name], and get some error:

KeyError: name not found
 in anonymous at /Users/jpwu/.julia/v0.4/Escher/src/cli/serve.jl:170
 in anonymous at /Users/jpwu/.julia/v0.4/Mux/src/Mux.jl:15
 in anonymous at /Users/jpwu/.julia/v0.4/Mux/src/Mux.jl:8
 in splitquery at /Users/jpwu/.julia/v0.4/Mux/src/basics.jl:28
 in anonymous at /Users/jpwu/.julia/v0.4/Mux/src/Mux.jl:8
 in wcatch at /Users/jpwu/.julia/v0.4/Mux/src/websockets_integration.jl:12
 in anonymous at /Users/jpwu/.julia/v0.4/Mux/src/Mux.jl:8
 in todict at /Users/jpwu/.julia/v0.4/Mux/src/basics.jl:21
 in anonymous at /Users/jpwu/.julia/v0.4/Mux/src/Mux.jl:12 (repeats 2 times)
 in anonymous at /Users/jpwu/.julia/v0.4/Mux/src/Mux.jl:8
 in anonymous at /Users/jpwu/.julia/v0.4/Mux/src/server.jl:38
 in handle at /Users/jpwu/.julia/v0.4/WebSockets/src/WebSockets.jl:382
 in on_message_complete at /Users/jpwu/.julia/v0.4/HttpServer/src/HttpServer.jl:393
 in on_message_complete at /Users/jpwu/.julia/v0.4/HttpServer/src/RequestParser.jl:104
 in http_parser_execute at /Users/jpwu/.julia/v0.4/HttpParser/src/HttpParser.jl:92
 in process_client at /Users/jpwu/.julia/v0.4/HttpServer/src/HttpServer.jl:365
 in anonymous at task.jl:447
rohitvarkey commented 8 years ago

@jingpengwu The problem is when the Dict is initialized there is no key name. This key is added only when the form is submitted, so before that you get an error. You have 2 options here.

  1. Apply a default value for name with inp = Signal(Dict(:name=>"")).
  2. Use get(dict, :name, "") instead of dict[:name] so as to prevent this error.
xiuliren commented 8 years ago

@rohitvarkey Thanks a lot! The second solution sounds better, and it works pretty well.