strapi-plugin-multi-select icon indicating copy to clipboard operation
strapi-plugin-multi-select copied to clipboard

Default value

Open matteocattelan opened this issue 2 years ago • 2 comments

Hi, is possible for required field set a default value?

Thanks a lot. Great Job!!

matteocattelan avatar Sep 01 '23 06:09 matteocattelan

I found the solution:

strapi-plugin-multi-select/admin/src/components/MultiSelect/index.js const sanitizedValue = useMemo(() => { let parsedValue try { parsedValue = JSON.parse(value || attribute['default']) } catch (e) { parsedValue = [] } return Array.isArray(parsedValue) ? possibleOptions.filter((option) => parsedValue.some((val) => option.value === val), ) : [] }, [value, possibleOptions])

in json of configuration can use this:

"options": [ "A:a", "B:b", "C": c" ], "required": true, "default": ["a"],

Is possibile include this code in the distribution? Thanks

matteocattelan avatar Sep 01 '23 10:09 matteocattelan

@Zaydme ping? Would be amazing to have this feature

Edit: I also created a pull request, if its fine a merge would be amazing https://github.com/Zaydme/strapi-plugin-multi-select/pull/19

FlashThePlayer avatar Oct 05 '23 13:10 FlashThePlayer

closed in https://github.com/Zaydme/strapi-plugin-multi-select/commit/073af312d5bfba80ab5e005b0faa0b6631bc90c6 available in @2.1.0

Zaydme avatar Oct 10 '24 02:10 Zaydme