From 2fa965ef95799cd088928f6a14190089899f997a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Mon, 10 Jul 2023 22:22:38 +0200 Subject: [PATCH 1/4] form: never have value prop for input as undefined --- src/components/Form.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/Form.js b/src/components/Form.js index c643ece0ba88..9d7b79b7e0db 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -251,7 +251,7 @@ function Form(props) { // We want to initialize the input value if it's undefined if (_.isUndefined(inputValues[inputID])) { - inputValues[inputID] = defaultValue; + inputValues[inputID] = defaultValue || ''; } // We force the form to set the input value from the defaultValue props if there is a saved valid value From 7e09cc95197da841a3c2179ae89b840eccf51db6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Tue, 11 Jul 2023 12:57:22 +0200 Subject: [PATCH 2/4] fix defaultValue prop usage --- src/components/Form.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/Form.js b/src/components/Form.js index 9d7b79b7e0db..b82ff957a25f 100644 --- a/src/components/Form.js +++ b/src/components/Form.js @@ -283,6 +283,9 @@ function Form(props) { } }, value: inputValues[inputID], + // As the text input is controlled, we never set the defaultValue prop + // as this is already happening by the value prop. + defaultValue: undefined, errorText: errors[inputID] || fieldErrorMessage, onBlur: (event) => { // We delay the validation in order to prevent Checkbox loss of focus when From 9eb1f49946b45c15583dbbe6400f477e2a8abac4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Tue, 11 Jul 2023 17:25:03 +0200 Subject: [PATCH 3/4] remove defaultValue as its controlled by the form --- src/components/NewDatePicker/index.js | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/components/NewDatePicker/index.js b/src/components/NewDatePicker/index.js index b5dad7992bfb..ace4e2285309 100644 --- a/src/components/NewDatePicker/index.js +++ b/src/components/NewDatePicker/index.js @@ -49,11 +49,6 @@ class NewDatePicker extends React.Component { }; this.setDate = this.setDate.bind(this); - - // We're using uncontrolled input otherwise it won't be possible to - // raise change events with a date value - each change will produce a date - // and make us reset the text input - this.defaultValue = props.defaultValue ? moment(props.defaultValue).format(CONST.DATE.MOMENT_FORMAT_STRING) : ''; } /** @@ -76,7 +71,6 @@ class NewDatePicker extends React.Component { icon={Expensicons.Calendar} label={this.props.label} value={this.props.value || ''} - defaultValue={this.defaultValue} placeholder={this.props.placeholder || this.props.translate('common.dateFormat')} errorText={this.props.errorText} containerStyles={this.props.containerStyles} From a98c3ad2d2c01bca960cc9e7ef8b605dfcb6b222 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hanno=20J=2E=20G=C3=B6decke?= Date: Fri, 14 Jul 2023 14:54:35 +0200 Subject: [PATCH 4/4] remove default value as its handled by Form.js --- src/components/DatePicker/index.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/components/DatePicker/index.js b/src/components/DatePicker/index.js index 393ba1b34bc7..5d1d8442bf6d 100644 --- a/src/components/DatePicker/index.js +++ b/src/components/DatePicker/index.js @@ -19,8 +19,6 @@ class DatePicker extends React.Component { this.setDate = this.setDate.bind(this); this.showDatepicker = this.showDatepicker.bind(this); - - this.defaultValue = props.defaultValue ? moment(props.defaultValue).format(CONST.DATE.MOMENT_FORMAT_STRING) : ''; } componentDidMount() { @@ -75,7 +73,6 @@ class DatePicker extends React.Component { label={this.props.label} onInputChange={this.setDate} value={this.props.value} - defaultValue={this.defaultValue} placeholder={this.props.placeholder} errorText={this.props.errorText} containerStyles={this.props.containerStyles}