Hello there,
I have recently asked my question here, and based on the answers I got some results.
So far I have the basic structure of what I want. I would like to add some more functionalities there, but have some more questions:
-
Is it possible to retrieve the list items without considering case sensitivity?
-
Can i make the retrieved list item linked to another list item, and when clicked only the linked item appears?
-
Can I make all the list items linked to some headlines? for example in my list there is one list item “this is our first sentences.”, Now, I would like to link this list item to another list Item called “first sentences”. and when I search for the first list item, the second list item appears?
-
How to clear list items, when there is no text on the TextBox?
I am ready to explain anything if its not clear.
Thank You.
My Source Code:
module Main exposing (main)
import Browser
import Html exposing (Html, Attribute, div, input, text,p,h1,br,h2,button)
import Html.Attributes exposing (..)
import Html.Events exposing (onInput,onClick)
type alias Model =
{ sentences : List String
, results : List String
}
sentences : List String
sentences =
[ "Hello there this is our first sentence."
, "this is the second sentence."
, "in our village its night"
, "and this is the fourth one."
, "this is the second sentence."
, "there is no third number for the sentence."
, "the box office results were crazy."
, "a quick brown fox jumps over the lazy dog"
, "Jumanji Jungalee"
, "our privacy policy"
]
initialModel : Model
initialModel =
{ sentences = sentences
, results = []
}
type Msg =
WordEntered String
update : Msg -> Model -> Model
update msg model =
case msg of
WordEntered word ->
( { model
| results =
model.sentences
|> List.filter (String.contains word)
}
)
rowItem: String -> Html Msg
rowItem id =
div [style "background-color" "#AFEEEE"
,style "border" "1px solid white",style "border-radius" "10px"
,style "padding" "10px"
]
[ text id ]
view : Model -> Html Msg
view model =
let
results =
model.results
|> List.map
(\ result ->
div[] []
)
in
div [ style "text-align" "center"]
[ h2 [ style "background-color" "#8B0000", style "border" "2px solid",style "color" "white"][text "Welcome to our chatbot!"]
, div[ style "border" "2px solid black" , style "border-radius" "10px", style "width" "50%"][
input [ placeholder "word", onInput WordEntered, style "padding" "5px 5px"] []
, button [style "background-color" "#8B0000", style "padding" "5px 5px", style "border-radius" "8px", style "color" "white"][text "Search"]
, div[](List.map rowItem model.results)
, br [] []
]]
main : Program () Model Msg
main =
Browser.sandbox
{ init = initialModel
, view = view
, update = update
}