-
Notifications
You must be signed in to change notification settings - Fork 1
Custom format validation #5
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- We also need to fix
normalizeString
to use the return value of the format parsing function. - Could you add a form example form using the
customFormats
setting?
src/Form/State.elm
Outdated
-} | ||
type alias Settings = | ||
{ customFormats : Dict String (String -> Result String String) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As we discussed, returning an error may be an overkill. Perhaps return Result () String
?
src/Form/Validation.elm
Outdated
|> Maybe.map (\validation -> validation value) | ||
|> Maybe.withDefault (Result.Ok value) | ||
in | ||
Result.mapError (\err -> error (Error.InvalidCustomFormat err)) customValidation |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it'd be good to report customFormat
, not err
, in Error.InvalidCustomFormat
. Our front-end may want to show a hint corresponding to which Personal number was requested (similar to what ID Check does):

Result.mapError (\err -> error (Error.InvalidCustomFormat err)) customValidation | |
Result.mapError (\_ -> error (Error.InvalidCustomFormat customFormat)) customValidation |
"not the correct format" | ||
|
||
InvalidCustomFormat _ -> | ||
"not the correct format" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@potocpav Shall we by the way give more information here regarding which format it is (which we underscore now) or leave is same as InvalidFormat?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should. The format string is internal, and should not be present in the UI. If users want to see more info, they need to implement their own view.
Added settings that contain provided custom format for validations.