Radiobuttons OHNE OK

This commit is contained in:
rxf
2025-10-27 17:24:48 +01:00
parent 1c153db116
commit dd32ad585e

View File

@@ -5,47 +5,29 @@ import Modal from './Modal'
export default function FandStattVer({left, right, title, onNext, radioName = "fst"}) { export default function FandStattVer({left, right, title, onNext, radioName = "fst"}) {
const { formData, updateFormData } = useFormData() const { formData, updateFormData } = useFormData()
const [auswahl, setAuswahl] = useState(formData.stattgefunden || '') const [auswahl, setAuswahl] = useState(formData.stattgefunden || '')
const [showModal, setShowModal] = useState(false)
const handleOK = () => { const handleRadioChange = (e) => {
if(!auswahl) { const value = e.target.value
setShowModal(true) setAuswahl(value)
return updateFormData('stattgefunden', value)
} onNext(value)
updateFormData('stattgefunden', auswahl)
onNext(auswahl)
}
const closeModal = () => {
setShowModal(false)
} }
return ( return (
<>
<section> <section>
<h3>{title}</h3> <h3>{title}</h3>
<div className="fstdiv"> <div className="fstdiv">
<label className="fsLabel"> <label className="fsLabel">
<input type="radio" name={radioName} value={left} checked={auswahl === left} <input type="radio" name={radioName} value={left} checked={auswahl === left}
onChange = {(e) => setAuswahl(e.target.value)} /> onChange={handleRadioChange} />
{left} {left}
</label> </label>
<label className="fsLabel"> <label className="fsLabel">
<input type="radio" name={radioName} value={right} checked={auswahl === right} <input type="radio" name={radioName} value={right} checked={auswahl === right}
onChange = {(e) => setAuswahl(e.target.value)} /> onChange={handleRadioChange} />
{right} {right}
</label> </label>
<button className="okbutton" onClick={handleOK}>OK</button>
</div> </div>
</section> </section>
<Modal
isOpen={showModal}
onClose={closeModal}
title="Auswahl erforderlich"
>
<p>Bitte eine Option wählen</p>
</Modal>
</>
) )
} }