Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in Autocomplete. #8

Merged
merged 2 commits into from
Dec 16, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 30 additions & 5 deletions WebSharper.JQueryUI.Tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ module internal Client =
)
Div [acc2] -< [button]

let TestAutocomplete () =
let conf = new AutocompleteConfiguration()
conf.Source <- [|"Apa"; "Beta"; "Zeta" ; "Zebra"|]
let RunAutocompleter conf =
let a = Autocomplete.New(Input [], conf)
a |> OnBeforeRender (fun _ -> Log "Before Render")
a |> OnAfterRender ( fun _ -> Log "After Render")
Expand All @@ -89,6 +87,32 @@ module internal Client =
bDestroy
]

let TestAutocomplete1 () =
let conf = new AutocompleteConfiguration()
conf.Source <| Listing [|"Apa"; "Beta"; "Zeta" ; "Zebra"|]
RunAutocompleter conf

let TestAutocomplete2 () =
let conf = new AutocompleteConfiguration()
let x : array<AutocompleteItem> =
[|{Label = "test"; Value = "value"}|]
conf.Source <| Items x
RunAutocompleter conf

let TestAutocomplete3 () =
let conf = new AutocompleteConfiguration()
let completef (_ : AutocompleteRequest, f : array<AutocompleteItem> -> unit) =
let x : array<AutocompleteItem> =
[|{Label = "test"; Value = "value"}|]
f x
conf.Source <| Callback completef
RunAutocompleter conf

let TestAutocomplete () =
TestAutocomplete1 ()
TestAutocomplete2 ()
TestAutocomplete3 ()

let TestButton () =
let b1 = JQueryUI.Button.New ("Click")
b1 |> OnAfterRender(fun _ -> Log "After Render")
Expand Down Expand Up @@ -288,7 +312,7 @@ module internal Client =
let img = Div [Style "background:url(http://www.look4design.co.uk/l4design/companies/light-iq/image14.jpg);height:100px;width:100px" ]
let resizable = Resizable.New img
resizable.OnStart (fun _ _ -> Log("Started!"))
resizable.OnResize (fun event ui ->
resizable.OnResize (fun event ui ->
if ui.Size.Width > 300 then
ui.Size.Width <- 300
if ui.Size.Height < 200 then
Expand All @@ -303,7 +327,8 @@ module internal Client =
let tab =
[
"Accordion", TestAccordion ()
"Autocomplete", TestAutocomplete ()
"Autocomplete1", TestAutocomplete1 ()
"Autocomplete2", TestAutocomplete2 ()
"Button", TestButton ()
"Datepicker", TestDatepicker ()
"Draggable", TestDraggable ()
Expand Down
38 changes: 23 additions & 15 deletions WebSharper.JQueryUI/Autocomplete.fs
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,24 @@ type AutocompleteItem =
Value : string
}

type AutocompleteCallback =
AutocompleteRequest * (AutocompleteItem[] -> unit) -> unit

[<JavaScript>]
type AutocompleteSource =
| Listing of array<string>
| Items of array<AutocompleteItem>
| Url of string
| Callback of AutocompleteCallback

type AutocompleteConfiguration[<JavaScript>]() =

[<DefaultValue>]
val mutable source : obj

[<Direct "this.source=function(x, y) { $scall([x, y]) }">]
let setCallback (scall : AutocompleteCallback) = ()

[<Name "appendTo">]
[<Stub>]
member val AppendTo = Unchecked.defaultof<string> with get, set
Expand All @@ -57,21 +73,13 @@ type AutocompleteConfiguration[<JavaScript>]() =
[<Stub>]
member val Position = Unchecked.defaultof<PositionConfiguration> with get, set

[<Name "source">]
[<Stub>]
member val Source = Unchecked.defaultof<array<string>> with get, set

[<Name "source">]
[<Stub>]
member val SourceItems = Unchecked.defaultof<array<AutocompleteItem>> with get, set

[<Name "source">]
[<Stub>]
member val SourceUrl = Unchecked.defaultof<string> with get, set

[<Name "source">]
[<Stub>]
member val SourceCallback = Unchecked.defaultof<AutocompleteRequest * (AutocompleteItem[] -> unit) -> unit> with get, set
[<JavaScript>]
member this.Source (s : AutocompleteSource) =
match s with
| Listing x -> this.source <- unbox x
| Items x -> this.source <- unbox x
| Url x -> this.source <- unbox x
| Callback x -> setCallback x

module internal AutocompleteInternal =
[<Inline "jQuery($el).autocomplete($conf)">]
Expand Down