fix bug que no se quitaban la clase de "p-invalid" después de registrar
This commit is contained in:
parent
93922d0766
commit
22e5de830a
|
@ -33,7 +33,7 @@ const Communities = () => {
|
||||||
const [cantonId, setCantonId] = useState(null);
|
const [cantonId, setCantonId] = useState(null);
|
||||||
const [districtsList, setDistrictsList] = useState([]);
|
const [districtsList, setDistrictsList] = useState([]);
|
||||||
const [districtId, setDistrictId] = useState(null);
|
const [districtId, setDistrictId] = useState(null);
|
||||||
const [codeHouses, setCodeHouses] = useState(null);
|
const [codeHouses, setCodeHouses] = useState('');
|
||||||
const [submitted, setSubmitted] = useState(false);
|
const [submitted, setSubmitted] = useState(false);
|
||||||
const toast = useRef(null);
|
const toast = useRef(null);
|
||||||
const dt = useRef(null);
|
const dt = useRef(null);
|
||||||
|
@ -142,7 +142,7 @@ const Communities = () => {
|
||||||
item.province = pList.find(p => p.code === item.province).name
|
item.province = pList.find(p => p.code === item.province).name
|
||||||
item.canton = cList.find(p => p.code === item.canton).name
|
item.canton = cList.find(p => p.code === item.canton).name
|
||||||
item.district = dList.find(p => p.code === item.district).name
|
item.district = dList.find(p => p.code === item.district).name
|
||||||
if(!item.id_admin){
|
if (!item.id_admin) {
|
||||||
item.name_admin = "Sin Administrador"
|
item.name_admin = "Sin Administrador"
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -151,15 +151,12 @@ const Communities = () => {
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
getCommunites();
|
getCommunites();
|
||||||
|
|
||||||
}, [])
|
}, [])
|
||||||
|
|
||||||
|
|
||||||
const saveCommunity = () => {
|
const saveCommunity = () => {
|
||||||
setSubmitted(true);
|
|
||||||
|
|
||||||
|
if (community.name.trim() ) {
|
||||||
if (community.name.trim()) {
|
|
||||||
let _communities = [...communitiesList];
|
let _communities = [...communitiesList];
|
||||||
let _community = { ...community };
|
let _community = { ...community };
|
||||||
_community.province = provinciaId;
|
_community.province = provinciaId;
|
||||||
|
@ -168,9 +165,9 @@ const Communities = () => {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
for (let i = 0; i < _community.num_houses; i++){
|
for (let i = 0; i < _community.num_houses; i++) {
|
||||||
_community.houses.push({
|
_community.houses.push({
|
||||||
number_house: codeHouses + (i+1),
|
number_house: codeHouses + (i + 1),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
// console.log(houses)
|
// console.log(houses)
|
||||||
|
@ -208,12 +205,16 @@ const Communities = () => {
|
||||||
setCodeHouses('');
|
setCodeHouses('');
|
||||||
|
|
||||||
setCommunity(emptyCommunity);
|
setCommunity(emptyCommunity);
|
||||||
|
|
||||||
})
|
})
|
||||||
.catch(
|
.catch(
|
||||||
err => console.log('Ocurrió un error con el fetch', err)
|
err => console.log('Ocurrió un error con el fetch', err)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
setSubmitted(true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -256,9 +257,9 @@ const Communities = () => {
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-home"></i>
|
<i className="pi pi-home"></i>
|
||||||
</span>
|
</span>
|
||||||
<InputText id="name" value={community.name} onChange={(e) => onInputChange(e, 'name')} required autoFocus className={classNames( submitted && community.name==='' ? 'p-invalid' : '' )} />
|
<InputText id="name" value={community.name} onChange={(e) => onInputChange(e, 'name')} required autoFocus className={submitted && community.name === '' ? 'p-invalid' : ''} />
|
||||||
</div>
|
</div>
|
||||||
{submitted && community.name==='' && <small className="p-invalid">Nombre es requirido.</small>}
|
{submitted && community.name === '' && <small className="p-invalid">Nombre es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="field col-12 md:col-6">
|
<div className="field col-12 md:col-6">
|
||||||
|
@ -268,7 +269,7 @@ const Communities = () => {
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-map-marker"></i>
|
<i className="pi pi-map-marker"></i>
|
||||||
</span>
|
</span>
|
||||||
<Dropdown placeholder="--Seleccione Provincia--" value={provinciaId} options={p} onChange={handleProvinces} required autoFocus className={classNames({ 'p-invalid': submitted && !provinciaId } )} />
|
<Dropdown placeholder="--Seleccione Provincia--" value={provinciaId} options={p} onChange={handleProvinces} required autoFocus className={classNames({ 'p-invalid': submitted && !provinciaId })} />
|
||||||
</div>
|
</div>
|
||||||
{submitted && !provinciaId && <small className="p-invalid">Provincia es requirido.</small>}
|
{submitted && !provinciaId && <small className="p-invalid">Provincia es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
|
@ -280,7 +281,7 @@ const Communities = () => {
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-map-marker"></i>
|
<i className="pi pi-map-marker"></i>
|
||||||
</span>
|
</span>
|
||||||
<Dropdown placeholder="--Seleccione Cantón--" value={cantonId} options={c} onChange={handleCanton} required autoFocus className={classNames({ 'p-invalid': submitted && !cantonId } )}/>
|
<Dropdown placeholder="--Seleccione Cantón--" value={cantonId} options={c} onChange={handleCanton} required autoFocus className={classNames({ 'p-invalid': submitted && !cantonId })} />
|
||||||
</div>
|
</div>
|
||||||
{submitted && !cantonId && <small className="p-invalid">Cantón es requirido.</small>}
|
{submitted && !cantonId && <small className="p-invalid">Cantón es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
|
@ -292,7 +293,7 @@ const Communities = () => {
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-map-marker"></i>
|
<i className="pi pi-map-marker"></i>
|
||||||
</span>
|
</span>
|
||||||
<Dropdown placeholder="--Seleccione Distrito--" value={districtId} options={d} onChange={handleDistrict} required autoFocus className={classNames({ 'p-invalid': submitted && !districtId } )}/>
|
<Dropdown placeholder="--Seleccione Distrito--" value={districtId} options={d} onChange={handleDistrict} required autoFocus className={classNames({ 'p-invalid': submitted && !districtId })} />
|
||||||
</div>
|
</div>
|
||||||
{submitted && !districtId && <small className="p-invalid">Distrito es requirido.</small>}
|
{submitted && !districtId && <small className="p-invalid">Distrito es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
|
@ -304,9 +305,9 @@ const Communities = () => {
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-phone"></i>
|
<i className="pi pi-phone"></i>
|
||||||
</span>
|
</span>
|
||||||
<InputText id="phone" value={community.phone} onChange={(e) => onInputChange(e, 'phone')} required autoFocus className={classNames({ 'p-invalid': submitted && community.phone==='' } )} />
|
<InputText id="phone" value={community.phone} onChange={(e) => onInputChange(e, 'phone')} required autoFocus className={classNames({ 'p-invalid': submitted && community.phone === '' })} />
|
||||||
</div>
|
</div>
|
||||||
{submitted && community.phone==='' && <small className="p-invalid">Número de teléfono es requirido.</small>}
|
{submitted && community.phone === '' && <small className="p-invalid">Número de teléfono es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="field col-12 md:col-6">
|
<div className="field col-12 md:col-6">
|
||||||
|
@ -316,7 +317,7 @@ const Communities = () => {
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-hashtag"></i>
|
<i className="pi pi-hashtag"></i>
|
||||||
</span>
|
</span>
|
||||||
<InputText id="num_houses" value={community.num_houses} onChange={(e) => onInputChange(e, 'num_houses')} required autoFocus className={classNames({ 'p-invalid': submitted && community.num_houses < 1 } )} />
|
<InputText id="num_houses" value={community.num_houses} onChange={(e) => onInputChange(e, 'num_houses')} required autoFocus className={classNames({ 'p-invalid': submitted && community.num_houses < 1 })} />
|
||||||
</div>
|
</div>
|
||||||
{submitted && community.num_houses < 1 && <small className="p-invalid">Número de viviendas es requirido y debe ser mayor que 0.</small>}
|
{submitted && community.num_houses < 1 && <small className="p-invalid">Número de viviendas es requirido y debe ser mayor que 0.</small>}
|
||||||
</div>
|
</div>
|
||||||
|
@ -328,9 +329,9 @@ const Communities = () => {
|
||||||
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
|
||||||
<i className="pi pi-hashtag"></i>
|
<i className="pi pi-hashtag"></i>
|
||||||
</span>
|
</span>
|
||||||
<InputText id="code_houses" value={codeHouses} onChange={handleCodeHouses} required autoFocus className={classNames({ 'p-invalid': submitted && !codeHouses } )} />
|
<InputText id="code_houses" value={codeHouses} onChange={handleCodeHouses} required autoFocus className={classNames({ 'p-invalid': submitted && codeHouses === '' })} />
|
||||||
</div>
|
</div>
|
||||||
{submitted && !codeHouses && <small className="p-invalid">El código para las viviendas es requirido.</small>}
|
{submitted && codeHouses === '' && <small className="p-invalid">El código para las viviendas es requirido.</small>}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-12 md:col-12 py-2">
|
<div className="col-12 md:col-12 py-2">
|
||||||
|
|
Loading…
Reference in New Issue