Compose form validations

93 Views Asked by At

I have several validation I'd like to add on the same input field. For example, a price field should not be less than 0 (check), and another that will query the DB (checkM)

    <$> areq priceField "Price" Nothing
    where priceField = check validateMinimumPrice intField

    <$> areq priceField "Price" Nothing    
    where priceField = checkM validatePriceFromDb intField

So I know how to add a single validation each time, but how can I compose those validation functions together?

Here's a gist with a simplified working form.

1

There are 1 best solutions below

0
amitaibu On

As answered by @user2407038 in this comment , the answer in my case is

<$> areq priceField "Price" Nothing
where priceField = (check validateMinimumPrice . checkM validateMinimumPriceInHandler) intField

I have updated the gist with the working solution