correjido comportmiento del formulario de editar
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
import { useState } from "react";
|
||||
import React from "react";
|
||||
|
||||
export default function EditarModal({ tipo, coord, show, close, setCoords }) {
|
||||
if (coord == null) return null;
|
||||
const [hasY, setHasY] = useState(coord.y !== null);
|
||||
|
||||
const [showY, setShowY] = React.useState(coord.y !== null);
|
||||
|
||||
const handleSubmit = (e) => {
|
||||
e.preventDefault();
|
||||
@@ -11,6 +13,7 @@ export default function EditarModal({ tipo, coord, show, close, setCoords }) {
|
||||
const y = formData.get("y");
|
||||
const z = formData.get("z");
|
||||
const descripcion = formData.get("descripcion");
|
||||
const hasY = formData.get("hasY") === "true";
|
||||
|
||||
let storedTipo = localStorage.getItem(tipo);
|
||||
if (storedTipo) {
|
||||
@@ -20,7 +23,7 @@ export default function EditarModal({ tipo, coord, show, close, setCoords }) {
|
||||
arr[index] = {
|
||||
...coord,
|
||||
x: Number(x),
|
||||
y: y ? Number(y) : null,
|
||||
y: hasY ? Number(y) : null,
|
||||
z: Number(z),
|
||||
descripcion: descripcion,
|
||||
};
|
||||
@@ -57,12 +60,11 @@ export default function EditarModal({ tipo, coord, show, close, setCoords }) {
|
||||
<div className="mb-3">
|
||||
<input
|
||||
type="checkbox"
|
||||
name="hasY"
|
||||
value="true"
|
||||
className="form-check-input me-2"
|
||||
checked={hasY}
|
||||
onChange={(e) => {
|
||||
coord.y = e.target.checked ? "0" : null;
|
||||
setHasY(e.target.checked);
|
||||
}}
|
||||
defaultChecked={coord.y !== null}
|
||||
onChange={(e) => setShowY(e.target.checked)}
|
||||
/>
|
||||
<label className="form-label">Lleva coordenada Y?</label>
|
||||
</div>
|
||||
@@ -75,7 +77,7 @@ export default function EditarModal({ tipo, coord, show, close, setCoords }) {
|
||||
defaultValue={coord.x}
|
||||
/>
|
||||
</div>
|
||||
{hasY && (
|
||||
{showY && (
|
||||
<div className="mb-3">
|
||||
<label className="form-label">Coordenada Y</label>
|
||||
<input
|
||||
|
||||
Reference in New Issue
Block a user