fix bug que no se quitaban la clase de "p-invalid" después de registrar

This commit is contained in:
Mariela 2022-07-22 00:03:01 -06:00
parent 93922d0766
commit 22e5de830a
1 changed files with 54 additions and 53 deletions

View File

@ -33,7 +33,7 @@ const Communities = () => {
const [cantonId, setCantonId] = useState(null);
const [districtsList, setDistrictsList] = useState([]);
const [districtId, setDistrictId] = useState(null);
const [codeHouses, setCodeHouses] = useState(null);
const [codeHouses, setCodeHouses] = useState('');
const [submitted, setSubmitted] = useState(false);
const toast = useRef(null);
const dt = useRef(null);
@ -151,13 +151,10 @@ const Communities = () => {
useEffect(() => {
getCommunites();
}, [])
const saveCommunity = () => {
setSubmitted(true);
if (community.name.trim() ) {
let _communities = [...communitiesList];
@ -208,12 +205,16 @@ const Communities = () => {
setCodeHouses('');
setCommunity(emptyCommunity);
})
.catch(
err => console.log('Ocurrió un error con el fetch', err)
);
} else {
setSubmitted(true);
}
}
@ -256,7 +257,7 @@ const Communities = () => {
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
<i className="pi pi-home"></i>
</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>
{submitted && community.name === '' && <small className="p-invalid">Nombre es requirido.</small>}
</div>
@ -328,9 +329,9 @@ const Communities = () => {
<span className="p-inputgroup-addon p-button p-icon-input-khaki">
<i className="pi pi-hashtag"></i>
</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>
{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 className="col-12 md:col-12 py-2">