add validation empty field on create and update form
This commit is contained in:
@ -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: '' });
|
||||
|
||||
@ -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: '' });
|
||||
};
|
||||
|
||||
@ -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'}>
|
||||
|
||||
@ -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,
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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: '' });
|
||||
};
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user