diff --git a/src/server/Server/Pages/Root.hs b/src/server/Server/Pages/Root.hs index 0e99579..45963e4 100644 --- a/src/server/Server/Pages/Root.hs +++ b/src/server/Server/Pages/Root.hs @@ -122,7 +122,7 @@ mkInput -> [Attribute] -- ^ Attributes -> Html () -- ^ Initial suggestions -> T.Text -- ^ input ID - -> Maybe FunGraph.FullyQualifiedType + -> Maybe FunGraph.FullyQualifiedType -- ^ initial value (optional) -> Html () mkInput jsTriggerFunctionName attrs initialSuggestions id' mInitialValue = do suggestions @@ -130,6 +130,7 @@ mkInput jsTriggerFunctionName attrs initialSuggestions id' mInitialValue = do [ name_ id' , id_ id' , type_ "search" + , value_ $ maybe mempty Server.Pages.Typeahead.renderSearchValue mInitialValue , list_ suggestionsId , hxGet_ "/typeahead" -- get suggestions from here (TODO: use something type-safe) , hxTarget_ $ "#" <> suggestionsId -- put suggestions here @@ -145,4 +146,4 @@ mkInput jsTriggerFunctionName attrs initialSuggestions id' mInitialValue = do datalist_ [ id_ suggestionsId , name_ suggestionsId - ] $ maybe mempty (Server.Pages.Typeahead.suggestionOption_ [selected_ ""]) mInitialValue <> initialSuggestions + ] initialSuggestions diff --git a/src/server/Server/Pages/Typeahead.hs b/src/server/Server/Pages/Typeahead.hs index 13f384e..46f386f 100644 --- a/src/server/Server/Pages/Typeahead.hs +++ b/src/server/Server/Pages/Typeahead.hs @@ -2,6 +2,7 @@ module Server.Pages.Typeahead ( mkHandler, HandlerType , suggestionOption_ +, renderSearchValue ) where @@ -109,7 +110,11 @@ suggestions prioTrie prefix = do suggestionOption_ :: [Attribute] -> FunGraph.FullyQualifiedType -> Html () suggestionOption_ extraAttrs fqt = option_ - ([ value_ $ FunGraph.renderFullyQualifiedType fqt + ([ value_ $ renderSearchValue fqt , label_ $ FunGraph.renderFullyQualifiedTypeNoPackage fqt ] ++ extraAttrs) "" + +-- ^ Render a value that goes into the src/dst search input +renderSearchValue :: FunGraph.FullyQualifiedType -> T.Text +renderSearchValue = FunGraph.renderFullyQualifiedType