-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathformExamples.tsx
More file actions
99 lines (96 loc) · 3.23 KB
/
formExamples.tsx
File metadata and controls
99 lines (96 loc) · 3.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import ButtonType from '@ui5/webcomponents/dist/types/ButtonType.js';
import InputType from '@ui5/webcomponents/dist/types/InputType.js';
import { useState } from 'react';
import {
ThemeProvider,
Form,
FormGroup,
FormItem,
Input,
Option,
Select,
Button,
MultiComboBox,
MultiComboBoxItem,
DatePicker,
Label,
} from '@ui5/webcomponents-react';
export function RegisterForm() {
const [email, setEmail] = useState('');
const [password, setPassword] = useState('');
const [country, setCountry] = useState('Germany');
const [birthday, setBirthday] = useState('');
const [payment, setPayment] = useState([]);
// todo: enable checkbox again once `required` issue is fixed: https://github.com/UI5/webcomponents/issues/7319
// const [terms, setTerms] = useState(false);
const handleSubmit = (e) => {
const values = {
email: email,
password: password,
country: country,
birthday: birthday,
payment: payment,
// terms: terms
};
alert(JSON.stringify(values, null, 2));
console.log(values);
//prevent page reload
e.preventDefault();
};
const handleEmailInput = (e) => {
setEmail(e.target.value);
};
const handlePasswordInput = (e) => {
setPassword(e.target.value);
};
const handleCountryChange = (e) => {
setCountry(e.detail.selectedOption.innerText);
};
const handleBirthdayChange = (e) => {
setBirthday(e.detail.value);
};
const handlePaymentSelectionChange = (e) => {
const selected = Object.values(e.detail.items).map((val) => val.text);
setPayment(selected);
};
// const handleTermsChange = (e) => {
// setTerms(e.target.checked);
// };
return (
<ThemeProvider>
<Form onSubmit={handleSubmit}>
<FormGroup titleText="Create Account">
<FormItem label={<Label required>Email</Label>}>
<Input name="email" required type={InputType.Email} value={email} onInput={handleEmailInput} />
</FormItem>
<FormItem label={<Label required>Password</Label>}>
<Input name="password" required type={InputType.Password} value={password} onInput={handlePasswordInput} />
</FormItem>
<FormItem label="Country">
<Select name="country" onChange={handleCountryChange}>
<Option>Germany</Option>
<Option>France</Option>
<Option>Italy</Option>
</Select>
</FormItem>
<FormItem label="Date of Birth">
<DatePicker value={birthday} onChange={handleBirthdayChange}></DatePicker>
</FormItem>
<FormItem label="Payment methods">
<MultiComboBox onSelectionChange={handlePaymentSelectionChange}>
<MultiComboBoxItem text="Credit card" />
<MultiComboBoxItem text="PayPal" />
<MultiComboBoxItem text="Bank transfer" />
</MultiComboBox>
</FormItem>
{/*<FormItem label="I accept the terms of service">*/}
{/* <CheckBox required name="terms" checked={terms} onChange={handleTermsChange} />*/}
{/*</FormItem>*/}
<FormItem label="">
<Button type={ButtonType.Submit}>Submit</Button>
</FormItem>
</FormGroup>
</Form>
</ThemeProvider>
);
}