Skip to content

Commit

Permalink
[Upd #101] State of the form is now accessible from Record
Browse files Browse the repository at this point in the history
  • Loading branch information
LaChope committed Mar 23, 2024
1 parent 175372b commit 41214c6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/components/record/Record.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Record extends React.Component {
this.recordForm = React.createRef();
this.state = {
isFormValid: false,
form: null,
};
}

Expand All @@ -42,6 +43,10 @@ class Record extends React.Component {
this.setState({ isFormValid });
};

updateForm = (form) => {
this.setState({ form });
};

render() {
const { record, formTemplate, currentUser } = this.props;

Expand Down Expand Up @@ -100,6 +105,8 @@ class Record extends React.Component {
formgen={formgen}
currentUser={this.props.currentUser}
isFormValid={this.isFormValid}
form={this.state.form}
updateForm={this.updateForm}
/>
) : null;
}
Expand Down
15 changes: 9 additions & 6 deletions src/components/record/RecordForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,8 @@ class RecordForm extends React.Component {
constructor(props) {
super(props);
this.i18n = this.props.i18n;
this.state = {
form: null,
};
this.form = this.props.form;
this.updateForm = this.props.updateForm;
this.refForm = React.createRef();
}

Expand All @@ -45,7 +44,9 @@ class RecordForm extends React.Component {

loadWizard() {
trackPromise(this.props.loadFormgen(this.props.record), "sform")
.then((data) => this.setState({ form: data }))
.then((data) => {
this.props.updateForm(data);
})
.catch(() => Logger.error("Received no valid wizard."));
}

Expand Down Expand Up @@ -105,10 +106,10 @@ class RecordForm extends React.Component {
return (
<>
<PromiseTrackingMask area="sform" />
{!!this.state.form && (
{!!this.props.form && (
<SForms
ref={this.refForm}
form={this.state.form}
form={this.props.form}
formData={this.props.record.question}
options={options}
fetchTypeAheadValues={this.fetchTypeAheadValues}
Expand All @@ -129,6 +130,8 @@ RecordForm.propTypes = {
loadFormgen: PropTypes.func,
formgen: PropTypes.object,
isFormValid: PropTypes.func,
form: PropTypes.object,
updateForm: PropTypes.func,
};

export default injectIntl(withI18n(RecordForm, { forwardRef: true }), { forwardRef: true });

0 comments on commit 41214c6

Please sign in to comment.