Browse Source

add validation

pull/2/head
wahyuun 1 year ago
parent
commit
8a45d7f5bb
  1. 30
      src/views/SimproV2/Divisi/DialogForm.js

30
src/views/SimproV2/Divisi/DialogForm.js

@ -29,8 +29,17 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
} }
}, [dataEdit, openDialog]) }, [dataEdit, openDialog])
const validation = () => {
if (!name || name === "") {
alert("Division Name cannot be empty!");
return true;
}
}
const handleSave = () => { const handleSave = () => {
let data = ''; let data = '';
const err = validation();
if (!err) {
if (typeDialog === "Save") { if (typeDialog === "Save") {
data = { data = {
name: name, name: name,
@ -49,25 +58,36 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
} }
setId(0) setId(0)
setDescription('') setDescription('')
setName('')
}
} }
const handleCancel = () => { const handleCancel = () => {
closeDialog('cancel', 'none') closeDialog('cancel', 'none')
setId(0) setId(0)
setDescription('') setDescription('')
setName('')
} }
const renderForm = () => { const renderForm = () => {
return ( return (
<Form> <Form>
<Row>
<Col md={12}>
<span style={{ color: "red" }}>*</span> Wajib diisi.
</Col>
</Row>
<Row> <Row>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">{t('name')}</Label> <Label className="capitalize">{t('name')}<span style={{ color: "red" }}>*</span></Label>
<Input type="text" value={name} onChange={(e) => setName(e.target.value)} placeholder={t('inputName')} /> <Input
type="text"
value={name}
onChange={(e) => setName(e.target.value)}
placeholder={t('inputName')}
/>
</FormGroup> </FormGroup>
</Col> </Col>
</Row>
<Row>
<Col md={6}> <Col md={6}>
<FormGroup> <FormGroup>
<Label className="capitalize">{t('nameDivision')}</Label> <Label className="capitalize">{t('nameDivision')}</Label>
@ -85,7 +105,7 @@ const DialogForm = ({ openDialog, closeDialog, toggleDialog, typeDialog, dataEdi
</Col> </Col>
</Row> </Row>
<Row> <Row>
<Col md={6}> <Col md={12}>
<FormGroup> <FormGroup>
<Label className="capitalize">{t('description')}</Label> <Label className="capitalize">{t('description')}</Label>
<Input row="4" type="textarea" value={description} onChange={(e) => setDescription(e.target.value)} placeholder={t('inputDescription')} /> <Input row="4" type="textarea" value={description} onChange={(e) => setDescription(e.target.value)} placeholder={t('inputDescription')} />

Loading…
Cancel
Save