Skip to content

Commit 92b1853

Browse files
committed
submitForm ref
1 parent aeccef7 commit 92b1853

2 files changed

Lines changed: 27 additions & 3 deletions

File tree

src/components/InputText.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function InputText(props) {
1212

1313
return (
1414
<View key={name}>
15-
<Text style={styles.text}>{`${meta.label} ${isMandatory ? '*' : ''}`}</Text>
15+
<Text style={[styles.text, meta.textStyle]}>{`${meta.label} ${isMandatory ? '*' : ''}`}</Text>
1616
<TextInput
1717
style={{ ...styles.textBox(meta.multiline, meta.numberOfLines), ...style }}
1818
value={value || ''}

src/index.js

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,32 @@ import { Button } from 'react-native-elements';
77
import { componentName, skipValidationForFields } from './constant';
88
import { getComponent, getValidator } from './componentMap';
99

10-
export default function DynamicForm({ formTemplate, onSubmit, buttonStyles, hideButtons=false, formValues = null, isTherapistQuestionnaire = true }) {
10+
11+
12+
13+
14+
const DynamicForm = React.forwardRef(
15+
({
16+
formTemplate, onSubmit, buttonStyles, hideButtons=false, formValues = null, isTherapistQuestionnaire = true
17+
}, ref) =>
18+
{
19+
20+
21+
React.useImperativeHandle(ref, () => ({
22+
submitForm: async function () {
23+
onSumbitButtonPress();
24+
},
25+
}));
26+
27+
28+
1129
const [formFields, setFormFields] = useState({});
1230
const [isValidFormFields, setValid] = useState(false);
1331
const mandatoryFields = formTemplate.data.filter(data => data.is_mandatory);
1432

33+
34+
35+
1536
useEffect(() => {
1637
formTemplate.data.sort((a, b) => a.index - b.index);
1738

@@ -152,7 +173,10 @@ export default function DynamicForm({ formTemplate, onSubmit, buttonStyles, hide
152173
}
153174
</View>
154175
);
155-
}
176+
});
177+
178+
179+
export default DynamicForm;
156180

157181
const styles = StyleSheet.create({
158182
container: {

0 commit comments

Comments
 (0)