Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

make select option clickable, but keep it from populating the select input view

I have a select with an option called "+ Create new"

When the user clicks on this option, I am showing a modal to create a new option, however I do not want this select option to render + create new after the option is clicked.

How can I keep the option "clickable" but keep it from populating the selects actual input view?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

here is the component

import React, {useState} from 'react';
import { Input } from 'reactstrap'

const TestComponent = () => {

const [upload, setUpload] = useState({
selectHeader: []
})

 const [showFieldModal, setShowFieldModal] = useState(false);

return (
              <Fragment>
                <Input
                  type="select"
                  name="selectHeader"
                  id="selectHeader"
                  onChange={({ target }) => {
                    if(target.value === "+ Create new") {
                      setShowFieldModal(!showFieldModal)
                    } else {
                      setUpload({...upload, selectHeader: [...upload.selectHeader, {value: target.value, index: index}]})
                    }
                  }}
                 >
                   <option>First name</option>
                   <option>Last name</option>
                 
                    <option>+ Create new</option> // make this clickable but dont allow it to show as the selects option when clicked....
                 </Input>
                </Fragment>
);
};

           export default TestComponent;

>Solution :

try, you need to empty the select value after clicking on the option, this might help you

onChange={({ target }) => {
     if(target.value === "+ Create new") {
        document.getElementById('selectHeader').value= " " ;
        setShowFieldModal(!showFieldModal)
     } else {
        setUpload({...upload, selectHeader: [...upload.selectHeader, {value: 
        target.value, index: index}]})
     }
}}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading