Skip to content

Commit

Permalink
Fix bug with input field not populating previous and default values o…
Browse files Browse the repository at this point in the history
…n the FormEdit UI (#156)

* populate defaultValue of initial and max length fields based on their data props in the InputPatternEdit.tsx UI.

* code formatting
  • Loading branch information
ethangardner authored Jun 5, 2024
1 parent e34c05a commit f5e94fc
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
/**
* @vitest-environment jsdom
*/
import { expect, it } from 'vitest'
import { expect, it } from 'vitest';

it('Is a placeholder test for now', () => {
expect(true).to.be.true;
})
});
// import { describeStories } from '../../../test-helper';
// import meta, * as stories from './CheckboxPatternEdit.stories';

// describeStories(meta, stories);
// describeStories(meta, stories);
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,13 @@ const EditComponent = ({ patternId }: { patternId: PatternId }) => {
const label = getFieldState('label');
const maxLength = getFieldState('maxLength');

const maxLengthAttributes =
pattern.data.maxLength > 0
? {
defaultValue: pattern.data.maxLength,
}
: {};

return (
<div className="grid-row grid-gap-1">
<div className="tablet:grid-col-6 mobile-lg:grid-col-12">
Expand All @@ -68,7 +75,7 @@ const EditComponent = ({ patternId }: { patternId: PatternId }) => {
></input>
</label>
</div>
<div className="tablet:grid-col-6 mobile-lg:grid-col-12">
<div className="tablet:grid-col-6 mobile-lg:grid-col-12 ohio">
<label
className={classnames('usa-label', {
'usa-label--error': initial.error,
Expand All @@ -85,6 +92,7 @@ const EditComponent = ({ patternId }: { patternId: PatternId }) => {
className="usa-input bg-primary-lighter text-bold"
id={fieldId('initial')}
type="text"
defaultValue={pattern.data.initial}
{...register('initial')}
></input>
</label>
Expand All @@ -105,6 +113,7 @@ const EditComponent = ({ patternId }: { patternId: PatternId }) => {
<input
className="usa-input bg-primary-lighter text-bold"
id={fieldId('maxLength')}
{...maxLengthAttributes}
type="text"
{...register('maxLength')}
></input>
Expand All @@ -113,14 +122,14 @@ const EditComponent = ({ patternId }: { patternId: PatternId }) => {
<div className="grid-col-12">
<PatternEditActions>
<span className="usa-checkbox">
<input
style={{ display: 'inline-block' }}
className="usa-checkbox__input bg-primary-lighter"
type="checkbox"
id={fieldId('required')}
{...register('required')}
defaultChecked={pattern.data.required}
/>
<input
style={{ display: 'inline-block' }}
className="usa-checkbox__input bg-primary-lighter"
type="checkbox"
id={fieldId('required')}
{...register('required')}
defaultChecked={pattern.data.required}
/>
<label
style={{ display: 'inline-block' }}
className="usa-checkbox__label"
Expand Down

0 comments on commit f5e94fc

Please sign in to comment.