Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions lib/components/molecules/Form/FieldCheckbox/FieldCheckbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,28 @@ type Props = {
id?: string,
className?: string,
name: string,
onChange?: Function,
};

const FieldCheckbox = ({ id, className, name, ...others }: Props): Node => (
const FieldCheckbox = ({ id, className, name, onChange, ...others }: Props): Node => (
<div className={className}>
<Field
name={name}
render={({ field }) => <InputChoice type="checkbox" id={id || name} {...field} {...others} />}
render={({ field, form }) => {
const { handleChange } = form;
return (
<InputChoice
type="checkbox"
id={id || name}
{...field}
{...others}
onChange={e => {
handleChange(e);
if (typeof onChange === 'function') onChange(e, form);
}}
/>
);
}}
/>
<ErrorMessage name={name} component={FieldError} />
</div>
Expand All @@ -26,6 +41,7 @@ const FieldCheckbox = ({ id, className, name, ...others }: Props): Node => (
FieldCheckbox.defaultProps = {
id: '',
className: '',
onChange: null,
};

export default styled(FieldCheckbox)`
Expand Down
25 changes: 24 additions & 1 deletion lib/components/molecules/Form/FieldInput/FieldInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ type Props = {
fieldProps?: Object,
value?: string | number,
placeholder?: string,
onChange?: Function,
onBlur?: Function,
};

const FieldInput = ({
Expand All @@ -26,6 +28,8 @@ const FieldInput = ({
type,
name,
label,
onChange,
onBlur,
labelProps,
fieldProps,
...others
Expand All @@ -39,7 +43,24 @@ const FieldInput = ({
id={id}
name={name}
type={type}
render={({ field }) => <Input type={type} {...others} {...field} />}
render={({ field, form }) => {
const { handleChange, handleBlur } = form;
return (
<Input
type={type}
{...others}
{...field}
onChange={e => {
handleChange(e);
if (typeof onChange === 'function') onChange(e, form);
}}
onBlur={e => {
handleBlur(e);
if (typeof onBlur === 'function') onBlur(e, form);
}}
/>
);
}}
{...fieldProps}
/>
<ErrorMessage name={name} component={FieldError} />
Expand All @@ -53,6 +74,8 @@ FieldInput.defaultProps = {
labelProps: {},
value: '',
fieldProps: {},
onChange: null,
onBlur: null,
};

export default styled(FieldInput)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ exports[`FieldInput should render correctly 1`] = `
className="c0"
fieldProps={Object {}}
labelProps={Object {}}
onBlur={null}
onChange={null}
placeholder=""
type="text"
value=""
Expand Down
25 changes: 17 additions & 8 deletions lib/components/molecules/Form/FieldRadioGroup/FieldRadioGroup.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import styles from './FieldRadioGroup.style';

type radioGroupProps = {
id: string,
onChange?: Function,
};

type Props = {
Expand All @@ -27,14 +28,22 @@ const FieldRadioGroup = ({ id, className, name, radioGroupArray, ...others }: Pr
<Field
key={radioGroup.id || `${name}_${index}`}
name={name}
render={({ field }) => (
<InputChoice
type="radio"
id={radioGroup.id || `${name}_${index}`}
{...field}
{...radioGroup}
/>
)}
render={({ field, form }) => {
const { handleChange } = form;
const { onChange } = radioGroup;
return (
<InputChoice
type="radio"
id={radioGroup.id || `${name}_${index}`}
onChange={e => {
handleChange(e);
if (typeof onChange === 'function') onChange(e, form);
}}
{...field}
{...radioGroup}
/>
);
}}
/>
))}
<ErrorMessage name={name} component={FieldError} />
Expand Down
17 changes: 16 additions & 1 deletion lib/components/molecules/Form/FieldSelect/FieldSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@ type Props = {
label: Node,
labelProps?: Object,
fieldProps?: Object,
onChange?: Function,
};

const FieldSelect = ({
id,
className,
name,
label,
onChange,
labelProps,
fieldProps,
...others
Expand All @@ -33,7 +35,19 @@ const FieldSelect = ({
<Field
name={name}
component="select"
render={({ field }) => <Select {...others} {...field} />}
render={({ field, form }) => {
const { handleChange } = form;
return (
<Select
{...others}
{...field}
onChange={e => {
handleChange(e);
if (typeof onChange === 'function') onChange(e, form);
}}
/>
);
}}
{...fieldProps}
/>
<ErrorMessage name={name} component={FieldError} />
Expand All @@ -43,6 +57,7 @@ const FieldSelect = ({
FieldSelect.defaultProps = {
labelProps: {},
fieldProps: {},
onChange: null,
};

export default styled(FieldSelect)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ exports[`FieldSelect should render correctly 1`] = `
className="c0"
fieldProps={Object {}}
labelProps={Object {}}
onChange={null}
/>
`;
21 changes: 20 additions & 1 deletion lib/components/molecules/Form/FieldTextarea/FieldTextarea.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ type Props = {
className?: string,
},
value?: string,
onChange?: string,
};

const FieldTextarea = ({
id,
className,
type,
name,
onChange,
label,
labelProps,
...others
Expand All @@ -32,7 +34,23 @@ const FieldTextarea = ({
<Label htmlFor={id} {...labelProps}>
{label}
</Label>
<Field id={id} name={name} render={({ field }) => <Textarea {...others} {...field} />} />
<Field
id={id}
name={name}
render={({ field, form }) => {
const { handleChange } = form;
return (
<Textarea
{...others}
{...field}
onChange={e => {
handleChange(e);
if (typeof onChange === 'function') onChange(e, form);
}}
/>
);
}}
/>
<ErrorMessage name={name} component={FieldError} />
</div>
);
Expand All @@ -41,6 +59,7 @@ FieldTextarea.defaultProps = {
className: '',
labelProps: {},
value: '',
onChange: null,
};

export default styled(FieldTextarea)`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ exports[`FieldTextarea should render correctly 1`] = `
<FieldTextarea
className="c0"
labelProps={Object {}}
onChange={null}
value=""
/>
`;
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ exports[`Form Component should render input field with no validation 1`] = `
label="User Name"
labelProps={Object {}}
name="username"
onBlur={null}
onChange={null}
placeholder=""
type="text"
value=""
Expand Down Expand Up @@ -669,6 +671,8 @@ exports[`Form Component should render input field with yupValidationSchema 1`] =
label="User Name"
labelProps={Object {}}
name="username"
onBlur={null}
onChange={null}
placeholder=""
type="text"
value=""
Expand Down Expand Up @@ -1360,6 +1364,8 @@ exports[`Form Component should render input text field 1`] = `
label="User Name"
labelProps={Object {}}
name="username"
onBlur={null}
onChange={null}
placeholder=""
type="text"
value=""
Expand Down Expand Up @@ -2120,6 +2126,7 @@ exports[`Form Component should render select field 1`] = `
label="Type of user"
labelProps={Object {}}
name="typeOfUser"
onChange={null}
options={
Array [
"Admin",
Expand Down