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

clearing the comment input after a successful comment post #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
10 changes: 6 additions & 4 deletions src/Page/Article.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Page.Article exposing (view, update, Model, Msg, init)
-}

import Html exposing (..)
import Html.Attributes exposing (class, href, id, placeholder, attribute, disabled)
import Html.Attributes exposing (class, href, id, placeholder, attribute, disabled, value)
import Html.Events exposing (onInput, onClick, onSubmit)
import Request.Article
import Request.Article.Comments
Expand Down Expand Up @@ -103,7 +103,7 @@ view session model =
]
, div [ class "row" ]
[ div [ class "col-xs-12 col-md-8 offset-md-2" ] <|
viewAddComment postingDisabled session.user
viewAddComment postingDisabled model.commentText session.user
:: List.map (viewComment session.user) model.comments
]
]
Expand Down Expand Up @@ -133,8 +133,8 @@ viewBanner errors article author maybeUser =
]


viewAddComment : Bool -> Maybe User -> Html Msg
viewAddComment postingDisabled maybeUser =
viewAddComment : Bool -> String -> Maybe User -> Html Msg
viewAddComment postingDisabled commentText maybeUser =
case maybeUser of
Nothing ->
p []
Expand All @@ -151,6 +151,7 @@ viewAddComment postingDisabled maybeUser =
[ class "form-control"
, placeholder "Write a comment..."
, attribute "rows" "3"
, value commentText

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a subtle bug—I just tried this same fix locally (before checking to see if someone else had already submitted a PR).

Put some text in the box, then move your cursor back to the beginning (or middle) and start mashing on the keyboard. The caret will at some point jump to the end of the text. See https://github.com/elm-lang/html/issues/55. 🙁

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. Did not know that.
I seems like there is no easy solution for that?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has been fixed in Elm 0.19. I'll merge this once that's released! 🎉

, onInput SetCommentText
]
[]
Expand Down Expand Up @@ -321,6 +322,7 @@ update session msg model =
{ model
| commentInFlight = False
, comments = comment :: model.comments
, commentText = ""
}
=> Cmd.none

Expand Down