-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #188 from open-formulieren/feature/4546-soft-requi…
…red-validation Add support for soft required validation in builder
- Loading branch information
Showing
23 changed files
with
497 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import {Meta, StoryObj} from '@storybook/react'; | ||
|
||
import {withFormik} from '@/sb-decorators'; | ||
|
||
import RichText from './rich-text'; | ||
|
||
export default { | ||
title: 'Formio/Builder/RichText', | ||
component: RichText, | ||
decorators: [withFormik], | ||
args: { | ||
name: 'richText', | ||
required: false, | ||
supportsBackendTemplating: false, | ||
}, | ||
parameters: { | ||
controls: {hideNoControlsWarning: true}, | ||
modal: {noModal: true}, | ||
formik: {initialValues: {richText: ''}}, | ||
}, | ||
} satisfies Meta<typeof RichText>; | ||
|
||
type Story = StoryObj<typeof RichText>; | ||
|
||
export const Default: Story = {}; | ||
|
||
export const WithBackendTemplatingSupport: Story = { | ||
args: { | ||
supportsBackendTemplating: true, | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import {useFormikContext} from 'formik'; | ||
import {useEffect} from 'react'; | ||
import {FormattedMessage, useIntl} from 'react-intl'; | ||
|
||
import {Checkbox} from '../../formio'; | ||
|
||
type ComponentWithRequiredOptions = { | ||
validate?: { | ||
required?: boolean; | ||
}; | ||
openForms?: { | ||
softRequired?: boolean; | ||
}; | ||
}; | ||
|
||
const SoftRequired = () => { | ||
const intl = useIntl(); | ||
const {values, setFieldValue} = useFormikContext<ComponentWithRequiredOptions>(); | ||
|
||
const isRequired = values?.validate?.required ?? false; | ||
const isSoftRequired = values?.openForms?.softRequired ?? false; | ||
|
||
// if the field is hard required, we must disable the soft required option, and | ||
// synchronize the softRequired to uncheck the option (if needed) | ||
useEffect(() => { | ||
if (isRequired && isSoftRequired) { | ||
setFieldValue('openForms.softRequired', false); | ||
} | ||
}, [setFieldValue, isRequired, isSoftRequired]); | ||
|
||
const tooltip = intl.formatMessage({ | ||
description: "Tooltip for 'openForms.softRequired' builder field", | ||
defaultMessage: `Soft required fields should be filled out, but empty values don't | ||
block the users' progress. Sometimes this is needed for legal reasons. A component | ||
cannot be hard and soft required at the same time.`, | ||
}); | ||
return ( | ||
<Checkbox | ||
name="openForms.softRequired" | ||
label={ | ||
<FormattedMessage | ||
description="Label for 'openForms.softRequired' builder field" | ||
defaultMessage="Soft required" | ||
/> | ||
} | ||
tooltip={tooltip} | ||
disabled={isRequired} | ||
/> | ||
); | ||
}; | ||
|
||
export default SoftRequired; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.