Home > front end >  how can i separate the two values
how can i separate the two values

Time:02-17

Form Option:

<Form.Group className="mb-3">
        <Form.Select
          as="select"
          onChange={(e) => {
            setCodigos(e.target.value);
          }}
     >
          <option value="">Código de Manutenção</option>
          {dataCodigos.map((doc) => (
            <option
              key={doc.id}
              value={`${doc.codigo} - ${doc.observacoes}`}
           
            >
              {`${doc.codigo} - ${
                doc.observacoes ? doc.observacoes : "Sem Observação"
              }`}
            </option>
          ))}
        </Form.Select>
      </Form.Group>

I map the options from firebase, and i want to save the doc.codigo and doc.observacoes separate. This way i save the data together

value={`${doc.codigo} - ${doc.observacoes}`} 

setCodigos(e.target.value)

CodePudding user response:

onChange event needs to use the split method. Below is the code

<select className="form-control form-control-sm"
      onChange={(e) => {
      var arr = e.target.value.split("-");
      setCodigos({codigo: arr[0],observacoes: arr[1]});
 }}
  • Related