Skip to content

Commit d2333a2

Browse files
committed
add Checkbox field
1 parent aaa5602 commit d2333a2

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,5 @@ __pycache__/
1818
.vscode
1919
test
2020
.idea
21-
todo.md
21+
todo.md
22+
venv

frontend/packages/pydantic-forms/src/components/defaultComponentMatchers.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
LabelField,
1212
RadioField,
1313
TextAreaField,
14+
CheckboxField
1415
} from '@/components/fields';
1516
import {
1617
PydanticComponentMatcher,
@@ -115,5 +116,6 @@ const defaultComponentMatchers: PydanticComponentMatcher[] = [
115116
},
116117
},
117118
];
119+
118120
// If nothing matches, it defaults to Text field in the mapToComponent function
119121
export default defaultComponentMatchers;
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import { PydanticFormControlledElementProps } from '@/types';
2+
3+
export const CheckboxField = ({
4+
onChange,
5+
onBlur,
6+
value,
7+
name,
8+
pydanticFormField
9+
}: PydanticFormControlledElementProps) => {
10+
console.log(pydanticFormField);
11+
return (
12+
<input
13+
type="checkbox"
14+
checked={value}
15+
onChange={() => onChange(!value)}
16+
onBlur={onBlur}
17+
name={name}
18+
/>
19+
);
20+
};

frontend/packages/pydantic-forms/src/components/fields/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './FormRow';
33
export * from './TextField';
44
export * from './IntegerField';
55
export * from './TextAreaField';
6+
export * from './CheckboxField';
67
export * from './LabelField';
78
export * from './DividerField';
89
export * from './HiddenField';

frontend/packages/pydantic-forms/src/core/mapFieldToComponent.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,11 @@ export const getComponentMatcher = (
8484
return matcher(field);
8585
});
8686

87+
console.log('Matched component __' + matchedComponent?.matcher)
8788
if (matchedComponent) return matchedComponent;
8889

8990
// Defaults to textField when there are no matches
91+
console.log('No match found for field ' + field.id);
9092
return {
9193
id: 'textfield',
9294
ElementMatch: {

0 commit comments

Comments
 (0)