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

Show error if account already exists #830

Merged
merged 1 commit into from
Sep 9, 2022
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
24 changes: 22 additions & 2 deletions src/elm/Form.elm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Form exposing
, optional, introspect, list, mapValues, mapOutput, withValidationStrategy, ValidationStrategy(..)
, textField, richText, toggle, checkbox, radio, select, file, fileMultiple, datePicker, userPicker, userPickerMultiple, arbitrary, arbitraryWith, unsafeArbitrary
, view, viewWithoutSubmit, Model, init, Msg, update, updateValues, getValue, hasFieldsLoading, msgToString
, withDisabled
, withDisabled, withShowAllErrors
, isDisabled, isShowingAllErrors
, parse
)
Expand Down Expand Up @@ -88,7 +88,7 @@ documentation if you're stuck.

### Changing attributes and state

@docs withDisabled
@docs withDisabled, withShowAllErrors


### Checking attributes and state
Expand Down Expand Up @@ -1023,6 +1023,26 @@ withDisabled disabled (Model model) =
Model { model | disabled = disabled }


{-| Control whether the form should show all errors or not. This is useful when
you want to show all errors after the user tried to submit the form, and you
have some custom action that doesn't automatically trigger all of the errors.
-}
withShowAllErrors : Bool -> Model values -> Model values
withShowAllErrors showAllErrors (Model model) =
let
(ErrorTracking errorTracking) =
model.errorTracking
in
Model
{ model
| errorTracking =
ErrorTracking
{ errorTracking
| showAllErrors = showAllErrors
}
}


{-| Checks if the form is disabled. It's useful to disable submit buttons when
using `viewWithoutSubmit` or when some parts of the UI should be disabled when
the form is disabled.
Expand Down
15 changes: 14 additions & 1 deletion src/elm/Page/Register.elm
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,19 @@ formOutputDecoder =
]


withShowAllErrors : Bool -> FormModel -> FormModel
withShowAllErrors showAllErrors formModel =
case formModel of
NaturalForm form ->
NaturalForm (Form.withShowAllErrors showAllErrors form)

JuridicalForm form ->
JuridicalForm (Form.withShowAllErrors showAllErrors form)

DefaultForm form ->
DefaultForm (Form.withShowAllErrors showAllErrors form)


type alias SignUpFields =
{ name : String
, email : String
Expand Down Expand Up @@ -619,7 +632,7 @@ update _ msg model ({ shared } as guest) =
Set.insert (Eos.nameToString account)
unavailableAccounts
}
formModel
(withShowAllErrors True formModel)

_ ->
model.status
Expand Down
16 changes: 9 additions & 7 deletions src/elm/Page/Register/Common.elm
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,18 @@ accountNameField ({ t } as translators) { unavailableAccounts } =
{ parser =
Form.Validate.succeed
>> Form.Validate.eosName
>> Form.Validate.custom
(\accountName ->
if Set.member (Eos.Account.nameToString accountName) unavailableAccounts then
Err (\translators_ -> translators_.t "error.alreadyTaken")

else
Ok accountName
)
>> Form.Validate.validate translators
, value = .account
, update = \account input -> { input | account = account }
, externalError =
\{ account } ->
if Set.member account unavailableAccounts then
Just (t "error.alreadyTaken")

else
Nothing
, externalError = always Nothing
}


Expand Down