Skip to content

Commit 6fbe80c

Browse files
Pablo Panerojrcastro2
authored andcommitted
array field: show empty value only once
Co-authored-by: Javier Romero Castro <[email protected]>
1 parent 17bf9e9 commit 6fbe80c

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/lib/forms/ArrayField.js

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ export class ArrayField extends Component {
2020
this.state = {
2121
// Chosen because it will never cross with 0-indexed pre-existing keys.
2222
nextKey: -1,
23+
hasBeenShown: false,
2324
};
2425
}
2526

@@ -41,10 +42,17 @@ export class ArrayField extends Component {
4142
*/
4243
getValues = (values, fieldPath) => {
4344
const { requiredOptions, defaultNewValue, showEmptyValue } = this.props;
45+
const { hasBeenShown } = this.state;
4446
const existingValues = getIn(values, fieldPath, []);
4547

46-
if (_isEmpty(requiredOptions) && _isEmpty(existingValues) && showEmptyValue) {
48+
if (
49+
!hasBeenShown &&
50+
_isEmpty(requiredOptions) &&
51+
_isEmpty(existingValues) &&
52+
showEmptyValue
53+
) {
4754
existingValues.push({ __key: existingValues.length, ...defaultNewValue });
55+
this.setState({ hasBeenShown: true });
4856
}
4957

5058
for (const requiredOption of requiredOptions) {

0 commit comments

Comments
 (0)