react-images-upload icon indicating copy to clipboard operation
react-images-upload copied to clipboard

Allow one Image select

Open osamakhanedu opened this issue 7 years ago • 13 comments

how can config component so it allow only selection of single image currently can select multiple images

osamakhanedu avatar Jul 18 '18 06:07 osamakhanedu

you can use prop singleImage={true}. It is there, but not showing in the documentation at the moment.

ivnnv avatar Jul 18 '18 14:07 ivnnv

i am setting singleImage={true} but its not working it is selecting more then one images and showing there preview. i only want to show preview of one image

osamakhanedu avatar Jul 20 '18 09:07 osamakhanedu

@osamakhanedu me too

xizzat avatar Aug 10 '18 13:08 xizzat

using singleImage={true} is restricting from selecting multiple images at a time. But still multiple images can be selected by one at a time.

nerdsquirrel avatar Sep 05 '18 06:09 nerdsquirrel

Maybe someone who worked with the Component might figure out how to implement a behaviour that only allows for a single Image to be added at a time (Just like singleImage={true} already does.) and whenever another is selected it removes the Image that's already there, only to replace it with the new one. Since this seems more like the intended way adding a singe Image would work, I propose to make this new behaviour work with the singleImage prop.

dmitrijBerg avatar Nov 24 '18 13:11 dmitrijBerg

A quick solution would be to disable the button when there's an image.

Adding the following to the <button /> element should do the trick

disabled={this.props.singleImage && this.state.files[0]}

juusaw avatar Dec 11 '18 14:12 juusaw

@juusaw Where are you see the button ? Or you change the the source component code ?

vsshaposhnikov avatar Dec 13 '18 08:12 vsshaposhnikov

That's internal to the library, yes. So an update to the library would be required.

juusaw avatar Dec 13 '18 08:12 juusaw

For fix this issue need to add if (this.props.singleImage) { dataURLs = []; files = []; } in onDropFile() method inside component.

vsshaposhnikov avatar Dec 13 '18 09:12 vsshaposhnikov

none of them suggestion working, @juusaw button is not disabling at all , even when I use disabled={true} @vsshaposhnikov if I paste this code in onDropfile() under compiled.js or index.js in the react-native-images-upload , it does not pick a single image.

amitbravo avatar Feb 12 '19 08:02 amitbravo

So far my best quick fix is to add display: 'none' to the buttonStyles prop if there are 1 or more images. This way the button does not appear.

taylorgannon avatar Jun 26 '19 21:06 taylorgannon

@taylorstyers Have you add the style directly on source code? or on your style css?

RobertStuff avatar Aug 13 '19 06:08 RobertStuff

@taylorstyers buttonStyles only works on hard coded style. but when I put a function It doesn't work.. buttonStyles={{display: function()}} doesn't work buttonStyles={{display: 'none'}} working

RobertStuff avatar Aug 14 '19 07:08 RobertStuff