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