1
2
3
let selected = Var.Create None
let select = Doc.SelectOptional [] "" id ["1"; "2"] selected
selected.Value <- "3"

The last line raises the following exception, which results with Select containing no options at all:

1
2
3
4
5
6
7
8
9
10
11
WebSharper: Uncaught asynchronous exception Error: KeyNotFoundException
    at Function.$.Define.WebSharper.Exception.$.Class.New1 (http://localhost:8084/Scripts/WebSharper/WebSharper.Main.min.js:1:31360)
    at Object.$.Define.WebSharper.Operators.FailWith (http://localhost:8084/Scripts/WebSharper/WebSharper.Main.min.js:1:42221)
    at Object.$.Define.WebSharper.Seq.findIndex (http://localhost:8084/Scripts/WebSharper/WebSharper.Main.min.js:1:53361)
    at m9 (http://localhost:8084/Scripts/WebSharper/WebSharper.UI.Next.min.js:1:23224)
    at http://localhost:8084/Scripts/WebSharper/WebSharper.UI.Next.min.js:1:23327
    at Object.$.Define.WebSharper.UI.Next.DynamicAttrNode.$.Class.Sync (http://localhost:8084/Scripts/WebSharper/WebSharper.UI.Next.min.js:1:33952)
    at iD (http://localhost:8084/Scripts/WebSharper/WebSharper.UI.Next.min.js:1:14292)
    at Object.$.Define.WebSharper.Arrays.iter (http://localhost:8084/Scripts/WebSharper/WebSharper.Main.min.js:1:12251)
    at Object.$.Define.WebSharper.UI.Next.Attrs.Sync (http://localhost:8084/Scripts/WebSharper/WebSharper.UI.Next.min.js:1:14327)
    at Object.$.Define.WebSharper.UI.Next.Docs.SyncElement (http://localhost:8084/Scripts/WebSharper/WebSharper.UI.Next.min.js:1:31620)
  • Vasily Kirichenko

    Found a workaround:

    1
    2
    3
    4
    5
    6
    
    selected.Lens 
        (fun x -> x) 
        (fun _ newVal -> 
             match newVal with
             | Some newVal when all |> List.exists ((=) newVal) -> Some newVal
             | _ -> None)

    I'm not sure what behavior is better by default though.