Skip to content
This repository has been archived by the owner on Jan 16, 2024. It is now read-only.

remove ref from for get the data in TargetContainer #2625

Closed
wants to merge 1 commit into from
Closed
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
5 changes: 3 additions & 2 deletions app/components/Target/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default class Target extends Component {
label: countTarget !== 0 ? i18n.t('label.update') : i18n.t('label.save'),
initialValues: { countTarget, targetYear, targetComment }
};
this.formRef=React.createRef();
Copy link
Collaborator

@norbertschuler norbertschuler Aug 18, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I am looking for a universal solution we can use throughout our whole codebase I would like to ask what is the difference of this solution vs.

<form onSubmit={this.props.onSignUpClicked.bind(this, type, this.signupForm)}>
<TCombForm
ref={ref => (this.signupForm = ref)}
type={signupFormSchema[type]}
options={this.props.schemaOptions[type]}
value={this.props.formValue}
/>
<PrimaryButton
onClick={event => {
this.props.onSignUpClicked(
type,
this.signupForm,
this.state.recaptchaToken,
this.refreshToken
);
event.preventDefault();
}}
>
{i18n.t('label.signUp')}
</PrimaryButton>
</form>
- can you maybe try to develop one template I can then use within the whole codebase to use refs correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in container file we are using ref to access the tcombform ref.
I just remove that ref and added tcombform ref in callBack function

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then I assume this patch should be the template for doing it everywhere else now.

}
shouldComponentUpdate(nextProps) {
return JSON.stringify(nextProps) !== JSON.stringify(this.props);
Expand All @@ -52,12 +53,12 @@ export default class Target extends Component {
<TextHeading>{i18n.t('label.set_target')}</TextHeading>
<CardLayout>
<TCombForm
ref="setTargetForm"
ref={this.formRef}
type={targetFormSchema}
options={allSchemaOptions}
value={this.state.initialValues}
/>
<PrimaryButton onClick={this.props.onSubmitTarget}>
<PrimaryButton onClick={()=>this.props.onSubmitTarget(this.formRef.current)}>
{this.state.label}
</PrimaryButton>
</CardLayout>
Expand Down
5 changes: 3 additions & 2 deletions app/components/Target/index.native.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ export default class Target extends Component {
this.state = {
label: countTarget !== 0 ? i18n.t('label.update') : i18n.t('label.save')
};
this.formRef=React.createRef();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same question for the native apps implementation as for the web client. Can you give me an example implementation I can use everywhere for the native apps? What is the difference of this patch against

onSignUpClicked = type => {
if (this.signupForm.getValue()) {
Keyboard.dismiss();
}
// eslint-disable-next-line no-underscore-dangle
this.props.onSignUpClicked(type, this.signupForm);
};
plus
<Form
ref={ref => (this.signupForm = ref)}
type={signupFormSchema[!ProfileTypeParam ? Profiletype : type]}
options={
this.props.schemaOptions[!ProfileTypeParam ? Profiletype : type]
}
value={this.props.formValue}
/>
?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are using TCombForm therefor it will only allow to access the method using ref. if we need to optimise this then we need to change TCombForm to Formik form that we are using in tree registration

Copy link
Collaborator

@norbertschuler norbertschuler Aug 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The refactoring work to change all remaining old Tcomb forms to Formik is also still open in #2475 :-)

}

shouldComponentUpdate(nextProps) {
Expand All @@ -37,14 +38,14 @@ export default class Target extends Component {
style={{ flex: 1, marginTop: Platform.OS === 'ios' ? 140 : 100 }}
>
<Form
ref={'setTargetForm'}
ref={this.formRef}
type={targetFormSchema}
options={this.props.schemaOptions}
value={this.props.treecounter}
/>
</CardLayout>
<PrimaryButton
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw. this is one example of a form where the ActivityIndicator within the PrimaryButton is not yet integrated (compare #1837), so the user does not know if the API requests for updating his target is still working or the app is crashed ;-)

onClick={this.props.onSubmitTarget}
onClick={()=>this.props.onSubmitTarget(this.formRef.current)}
buttonStyle={{ marginTop: 10 }}
>
{this.state.label}
Expand Down
13 changes: 3 additions & 10 deletions app/containers/TargetContainer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,8 @@ class TargetContainer extends React.Component {
};
this.onSubmitTarget = this.onSubmitTarget.bind(this);
}
onSubmitTarget = () => {
/* debug(
'\x1b[45m targetCOntainer',
this.refs.targetContainer.refs.setTargetForm.validate
); */
//debug('\x1b[0m');
//debug(this.refs.targetContainer.refs.setTargetForm.validate());
let value = this.refs.targetContainer.refs.setTargetForm.getValue();
onSubmitTarget = (formRef) => {
let value = formRef.getValue();
if (value) {
this.props
.SubmitTarget(value, this.props.navigation)
Expand All @@ -41,7 +35,7 @@ class TargetContainer extends React.Component {
}
},
() => {
this.refs.targetContainer.refs.setTargetForm.validate();
formRef.validate();
}
);
});
Expand All @@ -51,7 +45,6 @@ class TargetContainer extends React.Component {
render() {
return (
<Target
ref={'targetContainer'}
treecounter={this.props.treecounter}
schemaOptions={this.state.schemaOptions}
onSubmitTarget={this.onSubmitTarget}
Expand Down