Skip to content

Commit d089b2b

Browse files
authored
Merge pull request #15 from fullstacklabs/GDCM-1158
GDCM-1158 For email text field, Default to null when imput is an empty string.
2 parents 9e930e8 + 41107f6 commit d089b2b

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/DForm.test.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ const renderForm = (props, options = {}) =>
9898
render(
9999
<DForm
100100
form={form}
101-
initialSectionIndex={0}
101+
sectionIndex={options.initialSectionIndex || 0}
102102
answers={[]}
103103
formikValues={{}}
104104
formikTouched={{}}
@@ -199,7 +199,7 @@ const renderForm = (props, options = {}) =>
199199
)
200200

201201
test('renders form section', async () => {
202-
renderForm({ initialSectionIndex: 1 })
202+
renderForm(null, { initialSectionIndex: 1 })
203203
expect(screen.queryByTestId('field-1')).toHaveTextContent('I am a text field')
204204
expect(screen.queryByTestId('field-2')).toHaveTextContent(
205205
'I am a number field'
@@ -216,7 +216,7 @@ test('renders form section', async () => {
216216
})
217217

218218
test('move between sections and validate', async () => {
219-
renderForm({ initialSectionIndex: 0 })
219+
renderForm()
220220
expect(screen.queryByTestId('field-8')).toHaveTextContent('I am a text field')
221221
expect(screen.queryByTestId('section-1')).toHaveTextContent('IS VALID')
222222
userEvent.click(screen.queryByTestId('move-to-next-section'))
@@ -240,7 +240,7 @@ test('move between sections and validate', async () => {
240240
})
241241

242242
test('values persitance when moving through sections', async () => {
243-
renderForm({ initialSectionIndex: 0 })
243+
renderForm();
244244
userEvent.type(screen.queryByTestId('field-input-8'), 'Some text answer 8')
245245
userEvent.click(screen.queryByTestId('move-to-next-section'))
246246
userEvent.type(screen.queryByTestId('field-input-1'), 'Some text answer 1')
@@ -262,7 +262,6 @@ test('form submit value map to answers', async () => {
262262
const onSubmit = jest.fn()
263263
renderForm(
264264
{
265-
initialSectionIndex: 0,
266265
onSubmit,
267266
},
268267
{

src/fields/DynamicListField.test.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ const renderForm = (f) => {
6767
<div data-testid={`field-errors-${index}`}>{error}</div>
6868
</div>
6969
)}
70+
71+
renderNumberField={() => null}
72+
renderCodeField={() => null}
7073
/>
7174
)
7275
}

src/helpers/formMapper.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ const mapFormValueToAnswer = (
200200
return []
201201
}
202202

203+
if (field.fieldType === 'text' && field?.schema?.format === 'email' && !value) {
204+
return []
205+
}
206+
203207
return [{ fieldId: intFieldId, value }]
204208
}
205209

0 commit comments

Comments
 (0)