From 80e8f33c97bd091c99880042c5e36773de4db4ad Mon Sep 17 00:00:00 2001 From: Paulo Viana Date: Sat, 20 Feb 2021 15:50:30 -0400 Subject: [PATCH 1/5] feat: add disable options to SelectArrayInput commit 8d8e3f753c04c3456ab495f41c0bbec70da9c3a5 Author: Paulo Viana Date: Sat Feb 20 15:45:13 2021 -0400 feat: add documentation commit fce13066a861cc26c8eced4f9ea1a0c1c5fbaf97 Author: Paulo Viana Date: Sat Feb 20 13:28:33 2021 -0400 feat: add disableValue prop to useChoices commit 0db4dba9290e603f85b9fe58c7c6d374b72010e8 Author: Paulo Viana Date: Sat Feb 20 11:21:00 2021 -0400 feat: add disabled selectArrayInput unit test commit 1c1f7a8c62a8597712c8f0ba8d977bffd26d3ffd Author: Paulo Viana Date: Fri Feb 19 08:33:51 2021 -0400 feat: remove optionDisable commit 03a88a8c83c2fe8f4404d645925ac4c8442ba647 Author: Paulo Viana Date: Fri Feb 19 08:31:48 2021 -0400 feat: add disabled option to menuItem commit ab59e7263ada0efa317a348aae1aed20224676f8 Author: Paulo Viana Date: Thu Feb 18 23:31:31 2021 -0400 feat: add disabled choices to selectArrayInput --- docs/Inputs.md | 22 ++++++++++++++++++ examples/demo/src/segments/data.ts | 6 ++++- examples/demo/src/visitors/SegmentsInput.tsx | 1 + packages/ra-core/src/form/useChoices.ts | 7 ++++++ .../src/input/SelectArrayInput.spec.tsx | 23 +++++++++++++++++++ .../src/input/SelectArrayInput.tsx | 10 ++++++-- 6 files changed, 66 insertions(+), 3 deletions(-) diff --git a/docs/Inputs.md b/docs/Inputs.md index e9b620929e2..5cabaeef84c 100644 --- a/docs/Inputs.md +++ b/docs/Inputs.md @@ -1338,6 +1338,28 @@ const choices = [ ]; ``` +You can set disabled values by setting the `disabled` property of one item: + +```jsx +const choices = [ + { _id: 123, full_name: 'Leo Tolstoi', sex: 'M' }, + { _id: 456, full_name: 'Jane Austen', sex: 'F' }, + { _id: 1, full_name: 'System Administrator', sex: 'F', disabled: true }, +]; + +``` + +You can use a custom field name by setting `disableValue` prop: + +```jsx +const choices = [ + { _id: 123, full_name: 'Leo Tolstoi', sex: 'M' }, + { _id: 456, full_name: 'Jane Austen', sex: 'F' }, + { _id: 987, full_name: 'Jack Harden', sex: 'M', not_available: true }, +]; + +``` + Lastly, use the `options` attribute if you want to override any of the `