Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set default value from existing resource #44

Open
andresfmm opened this issue May 29, 2023 · 0 comments
Open

set default value from existing resource #44

andresfmm opened this issue May 29, 2023 · 0 comments

Comments

@andresfmm
Copy link

i hope can help someone if you want set value default from a existing resource you can this way how explin in documentation

const [countries, setCountries] = React.useState([
{ id: '22946344-f6be-11ed-8207-9828a60f7a9e', name: 'node js'},
{ id: '123456789', name: 'php'}
]);

const id = '22946344-f6be-11ed-8207-9828a60f7a9e';

countries.forEach(function(item){

    if ( item.id ==  id ) {
         item.checked = true;
    }

});

setCountries(countries);

<Select2
style={{ borderRadius: 5, marginTop: 20 }}
isSelectSingle
cancelButtonText="Cancelar"
selectButtonText="Aceptar"
searchPlaceHolderText="Buscar"
colorTheme={theme.colors.primary}
popupTitle="Seleccione "
title="Selecionar barrio"
data={countries}
onSelect={(data:any) => {
setState(data)
}}
onRemoveItem={(data:any) => {
setState(data)
}}
/>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant