add validation empty field on create and update form

This commit is contained in:
Wikzyy
2025-03-17 11:06:58 +07:00
parent 075c89c163
commit aeea5c31af
14 changed files with 37 additions and 36 deletions

View File

@ -72,12 +72,12 @@ const AddDialog = () => {
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.name === '') {
if (formField.name.trim() === '') {
setAlert({ show: true, message: 'Please fill name field.' });
return;
}
doCreateMunicipio(e);
// doCreateMunicipio(e);
console.log(parsedUser.email);
console.log(formField);
setAlert({ show: false, message: '' });

View File

@ -77,7 +77,7 @@ const EditDialog = () => {
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.name === '') {
if (formField.name.trim() === '') {
setAlert({ show: true, message: 'Please fill name field.' });
return;
}
@ -88,7 +88,7 @@ const EditDialog = () => {
// created_at: formattedTime
// });
doUpdateMunicipios(e);
// doUpdateMunicipios(e);
console.log(formField);
setAlert({ show: false, message: '' });
};

View File

@ -29,8 +29,8 @@ const ListToolbar = () => {
<input
type="text"
placeholder="Search Municipios"
value={searchName}
onChange={(event) => setSearchName(event.target.value)}
value={(table.getColumn('name')?.getFilterValue() as string) ?? ''}
onChange={(event) => table.getColumn('name')?.setFilterValue(event.target.value)}
/>
</label>
<DefaultTooltip title={'Filter'} placement={'top'}>

View File

@ -113,8 +113,9 @@ const ManageMunicipiosProvider = ({ children }: { children: React.ReactNode }) =
}
},
{
accessorFn: (row) => row.name,
id: 'name',
// accessorFn: (row) => row.name,
// id: 'name',
accessorKey: 'name',
header: ({ column }) => <DataGridColumnHeader title="Municipios Name" column={column} />,
enableSorting: true,
enableHiding: false,

View File

@ -83,7 +83,7 @@ const AddDialog = () => {
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.name === '' || formField.municipio_id === 0) {
if (formField.name.trim() === '' || formField.municipio_id === 0) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;
}

View File

@ -83,7 +83,7 @@ const EditDialog = () => {
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.name === '' || formField.municipio_id === 0) {
if (formField.name.trim() === '' || formField.municipio_id === 0) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;
}

View File

@ -71,21 +71,21 @@ const AddDialog = () => {
e.preventDefault();
if (
formField.name === '' ||
formField.description === '' ||
formField.name.trim() === '' ||
formField.description.trim() === '' ||
formField.price_point === 0 ||
formField.price_cash === 0 ||
formField.cashback_point === 0 ||
formField.cashback_cash === 0 ||
formField.status === '' ||
formField.created_by === '' ||
formField.created_at === ''
formField.status.trim() === '' ||
formField.created_by.trim() === '' ||
formField.created_at.trim() === ''
) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;
}
doCreateProduct(e);
// doCreateProduct(e);
console.log(formField);
setAlert({ show: false, message: '' });
};

View File

@ -70,15 +70,15 @@ const EditDialog = () => {
e.preventDefault();
if (
formField.name === '' ||
formField.description === '' ||
formField.name.trim() === '' ||
formField.description.trim() === '' ||
formField.price_point === 0 ||
formField.price_cash === 0 ||
formField.cashback_point === 0 ||
formField.cashback_cash === 0 ||
formField.status === '' ||
formField.updated_by === '' ||
formField.updated_at === ''
formField.updated_by.trim() === '' ||
formField.updated_at.trim() === ''
) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;

View File

@ -61,7 +61,7 @@ const AddDialog = () => {
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.name === '') {
if (formField.name.trim() === '') {
setAlert({ show: true, message: 'Please fill name field.' });
return;
}

View File

@ -65,7 +65,7 @@ const EditDialog = () => {
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.name === '') {
if (formField.name.trim() === '') {
setAlert({ show: true, message: 'Please fill name field.' });
return;
}

View File

@ -100,12 +100,12 @@ const AddDialog = () => {
e.preventDefault();
if (
formField.name === '' ||
formField.description === '' ||
formField.type === '' ||
formField.status === '' ||
formField.transactionTypeId === '' ||
formField.agentId === ''
formField.name.trim() === '' ||
formField.description.trim() === '' ||
formField.type.trim() === '' ||
formField.status.trim() === '' ||
formField.transactionTypeId.trim() === '' ||
formField.agentId.trim() === ''
) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;

View File

@ -114,12 +114,12 @@ const EditDialog = () => {
e.preventDefault();
if (
formField.name === '' ||
formField.description === '' ||
formField.type === '' ||
formField.status === '' ||
formField.transactionTypeId === '' ||
formField.agentId === ''
formField.name.trim() === '' ||
formField.description.trim() === '' ||
formField.type.trim() === '' ||
formField.status.trim() === '' ||
formField.transactionTypeId.trim() === '' ||
formField.agentId.trim() === ''
) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;

View File

@ -62,7 +62,7 @@ const AddDialog = () => {
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.name === '' || formField.posto_adm_id === 0) {
if (formField.name.trim() === '' || formField.posto_adm_id === 0) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;
}

View File

@ -68,7 +68,7 @@ const EditDialog = () => {
const handleUpdate = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (formField.name === '' || formField.posto_adm_id === 0) {
if (formField.name.trim() === '' || formField.posto_adm_id === 0) {
setAlert({ show: true, message: 'Please fill in all required fields.' });
return;
}