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

Can't parse negatives number in forms #702

Closed
tonyx opened this issue Jun 20, 2018 · 0 comments
Closed

Can't parse negatives number in forms #702

tonyx opened this issue Jun 20, 2018 · 0 comments

Comments

@tonyx
Copy link

tonyx commented Jun 20, 2018

parse error in forms with decimal.

In Form.fs:

type MyForm = { Value: decimal }

In View.fs

{ Label = "Data"; Html = formInput (fun f -> <@ f.Value @>) [] }

entering a negative number like "-10" lead in the form lead to
"Cound not parse '-10' to Decimal"

workaround by using string, validate them by regexp, and convert the string to decimal

type MyForm = {
Value: string
}

let decimalNumberPattern =  matches  @"-{0,1}\d*(\.{0,1}\d*)" 

let priceAdjustment: Form<PriceAdjustment> = 
    Form ([
        TextProp ((fun f -> <@ f.Value   @>), [decimalNumberPattern])
    ],
[] )
@ademar ademar closed this as completed in 7308779 Jun 25, 2018
@ademar ademar changed the title can't parse negatives number in forms Can't parse negatives number in forms Jun 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant