Skip to content

Commit fac4029

Browse files
authored
Merge pull request #23 from workfloworchestrator/1710-Pydanticforms-basic--Boolean-checkbox-field
[1710] add Checkbox field
2 parents aaa5602 + 2a88e5a commit fac4029

File tree

5 files changed

+40
-3
lines changed

5 files changed

+40
-3
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

backend/main.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,10 @@ class TestForm(FormPage):
101101
label: Label = "Label"
102102
hidden: Hidden = "Hidden"
103103
# When there are > 3 choices a dropdown will be rendered
104-
dropdown: DropdownChoices = ("2")
104+
dropdown: DropdownChoices = "2"
105105
# When there are <= 3 choices a radio group will be rendered
106-
radio: RadioChoices = ("3")
106+
radio: RadioChoices = "3"
107+
checkbox: bool = True
107108

108109
form_data_1 = yield TestForm
109110

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* We will search for the first field that returns a positive match
55
*/
66
import {
7+
CheckboxField,
78
DividerField,
89
DropdownField,
910
HiddenField,
@@ -114,6 +115,17 @@ const defaultComponentMatchers: PydanticComponentMatcher[] = [
114115
);
115116
},
116117
},
118+
{
119+
id: 'checkbox',
120+
ElementMatch: {
121+
Element: CheckboxField,
122+
isControlledElement: true,
123+
},
124+
matcher(field) {
125+
return field.type === PydanticFormFieldType.BOOLEAN;
126+
},
127+
},
117128
];
129+
118130
// If nothing matches, it defaults to Text field in the mapToComponent function
119131
export default defaultComponentMatchers;
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import React from 'react';
2+
3+
import { PydanticFormControlledElementProps } from '@/types';
4+
5+
export const CheckboxField = ({
6+
onChange,
7+
onBlur,
8+
value,
9+
name,
10+
disabled,
11+
}: PydanticFormControlledElementProps) => {
12+
return (
13+
<input
14+
type="checkbox"
15+
checked={value}
16+
onChange={() => onChange(!value)}
17+
onBlur={onBlur}
18+
name={name}
19+
disabled={disabled}
20+
/>
21+
);
22+
};

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';

0 commit comments

Comments
 (0)