0

I have added the dropdown field and I have to show the value in dropdown which I send but in this ionselect it takes only one value on the drop down.

const intila={
    primary:[""]

  }
  const[primarySkill,setPrimary]=useState(intila);
  const handleChange=(event:any)=>{
    primarySkill.primary=event.target.value;
    setPrimary(primarySkill);}
const[isSuccess,setSuccess]=useState(false);
   const handleSubmit=(event:any)=>{
     dispatch(postPrimary())
   }
   if(customerData.primary.length>0&&!customerData.isLoading&&!isSuccess){
     for(var i=0;i<customerData.primary.length;i++){
      var primary=customerData.primary[i];     
       primarySkill.primary.push(primary);
      setPrimary(primarySkill); }
     setSuccess(true);
     console.log(primarySkill);
   }
  return (
    <div>
      <IonSelect  className="ion-padding" multiple={true} onIonChange={handleChange} value={primarySkill.primary}>
      {itemCustomers}
      </IonSelect>
      <IonButton onClick={handleSubmit}/>
    </div>)

The postPrimary have ["Customer 1","Customer 2"]

itemCustomer have [Customer 1,Customer 2,Customer 3,Customer 4,Customer 5[][1]

Here the image view for UI:[1]: https://i.stack.imgur.com/RdmYz.png

1 Answers1

0
  const handleChange=(event:any)=>{
    primarySkill.primary = event.detail.value;
    setPrimary(primarySkill);
  }

worked for me

Aaron Saunders
  • 33,180
  • 5
  • 60
  • 80
  • In handleSubmit ,I called the postPrimary in that function return two string of array Like Example:["Customer 1","Customer 2"].I am trying to set the two Customer on dropdown but it takes only Customer 2. – Shanthi Sannasi May 09 '20 at 05:43