Skip to content

Commit ba01e62

Browse files
authored
Menerjemahkan article.md
1 parent 7d08a94 commit ba01e62

File tree

1 file changed

+94
-94
lines changed

1 file changed

+94
-94
lines changed
Lines changed: 94 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
# Form properties and methods
1+
# Metode dan properti form
22

3-
Forms and control elements, such as `<input>` have a lot of special properties and events.
3+
Form dan elemen kontrol, contohnya seperti `<input>` memiliki banyak properti khusus dan event.
44

5-
Working with forms will be much more convenient when we learn them.
5+
Bekerja dengan form akan lebih mudah ketika kita mempelajarinya.
66

7-
## Navigation: form and elements
7+
## Navigasi: form dan elemen
88

9-
Document forms are members of the special collection `document.forms`.
9+
Form dokumen adalah anggota dari koleksi khusus `document.forms`.
1010

11-
That's a so-called "named collection": it's both named and ordered. We can use both the name or the number in the document to get the form.
11+
Itu disebut _"named collection"_: itu keduanya memiliki nama(name) dan terurut(index). Kita bisa menggunakan keduanya baik dengan nama atau nomor(index) pada dokumen untuk mendapatkan form.
1212

1313
```js no-beautify
1414
document.forms.my - the form with name="my"
1515
document.forms[0] - the first form in the document
1616
```
1717

18-
When we have a form, then any element is available in the named collection `form.elements`.
18+
Ketika kita mempunyai sebuah form, maka elemen apapun tersedia di dalam _named collection/koleksi nama_ `form.elements`.
1919

20-
For instance:
20+
Misalnya:
2121

2222
```html run height=40
2323
<form name="my">
24-
<input name="one" value="1">
25-
<input name="two" value="2">
24+
<input name="one" value="1" />
25+
<input name="two" value="2" />
2626
</form>
2727

2828
<script>
29-
// get the form
30-
let form = document.forms.my; // <form name="my"> element
29+
// dapatkan form
30+
let form = document.forms.my; // <form name="my"> elemen
3131
32-
// get the element
33-
let elem = form.elements.one; // <input name="one"> element
32+
// dapatkan element
33+
let elem = form.elements.one; // <input name="one"> elemen
3434
3535
alert(elem.value); // 1
3636
</script>
3737
```
3838

39-
There may be multiple elements with the same name, that's often the case with radio buttons.
39+
Ada suatu saat dimana ada beberapa elemen dengan nama yang sama, hal itu sering terjadi dengan _radio buttons_.
4040

41-
In that case `form.elements[name]` is a collection, for instance:
41+
Dalam hal tersebut `form.elements[name]`adalah sebuah _collection/koleksi_, misalnya:
4242

4343
```html run height=40
4444
<form>
@@ -57,13 +57,12 @@ alert(ageElems[0]); // [object HTMLInputElement]
5757
</script>
5858
```
5959

60-
These navigation properties do not depend on the tag structure. All control elements, no matter how deep they are in the form, are available in `form.elements`.
60+
Navigasi properti ini tidak bergantung pada struktur tag. Semua elemen kontrol, tak peduli seberapa dalam mereka didalam form, mereka tersedia di dalam `form.elements`.
6161

62+
````smart header="Fieldsets sebagai "subforms""
63+
Sebuah form mungkin punya satu atau banyak elemen `<fieldset>` didalamnya. Mereka juga punya `elements` properti yang mencatumkan form kontrol didalamnya.
6264
63-
````smart header="Fieldsets as \"subforms\""
64-
A form may have one or many `<fieldset>` elements inside it. They also have `elements` property that lists form controls inside them.
65-
66-
For instance:
65+
Misalnya:
6766
6867
```html run height=80
6968
<body>
@@ -81,57 +80,57 @@ For instance:
8180
let fieldset = form.elements.userFields;
8281
alert(fieldset); // HTMLFieldSetElement
8382
84-
// we can get the input by name both from the form and from the fieldset
83+
// kita bisa mendapatkan input dengan nama baik dari form maupun dari fieldset
8584
alert(fieldset.elements.login == form.elements.login); // true
8685
*/!*
8786
</script>
8887
</body>
8988
```
9089
````
9190

92-
````warn header="Shorter notation: `form.name`"
93-
There's a shorter notation: we can access the element as `form[index/name]`.
91+
````warn header="Shorter notation: `form.name`" Ada notasi yang lebih ringkas: kita bisa akses/mendapatkan elemen dengan `form[index/name]`.
9492

95-
In other words, instead of `form.elements.login` we can write `form.login`.
93+
Dengan kata lain, daripada menulisnya dengan `form.elements.login` kita bisa menulis `form.login`.
9694

97-
That also works, but there's a minor issue: if we access an element, and then change its `name`, then it is still available under the old name (as well as under the new one).
95+
Itu juga berkeja, tetapi disana ada sebuah kesalahan kecil: jika kita akses sebuah elemen, dan lalu mengubah `name`, maka elemen tersebut masih tersedia dengan nama lamanya (sama juga dengan nama barunya).
9896

99-
That's easy to see in an example:
97+
Itu akan lebih mudah saat kita lihat pada sebuah contoh:
10098

10199
```html run height=40
102100
<form id="form">
103-
<input name="login">
101+
<input name="login" />
104102
</form>
105103

106104
<script>
107-
alert(form.elements.login == form.login); // true, the same <input>
105+
alert(form.elements.login == form.login); // true, <input> yang sama
108106
109-
form.login.name = "username"; // change the name of the input
107+
form.login.name = "username"; // mengubah nama input
110108
111-
// form.elements updated the name:
112-
alert(form.elements.login); // undefined
113-
alert(form.elements.username); // input
109+
// form.elements telah mengupdate nama:
110+
alert(form.elements.login); // undefined (tidak terdefinisi)
111+
alert(form.elements.username); // input
114112
115-
*!*
116-
// form allows both names: the new one and the old one
117-
alert(form.username == form.login); // true
118-
*/!*
113+
*!*
114+
// form membolehkan kedua nama: yang baru dan yang lama
115+
alert(form.username == form.login); // true
116+
*/!*
119117
</script>
120118
```
121119

122-
That's usually not a problem, because we rarely change names of form elements.
120+
Itu biasanya bukan sebuah masalah, karena kita jarang mengubah nama dari elemen form.
123121

124122
````
125123
126124
## Backreference: element.form
127125
128-
For any element, the form is available as `element.form`. So a form references all elements, and elements reference the form.
126+
Untuk elemen apapun, form tersedia sebagai `element.form`. Jadi sebuah form mereferensikan semua elemen, dan elemen referensi dari form.
129127
130-
Here's the picture:
128+
129+
Ini gambarannya:
131130
132131
![](form-navigation.svg)
133132
134-
For instance:
133+
Misalnya:
135134
136135
```html run height=40
137136
<form id="form">
@@ -140,55 +139,55 @@ For instance:
140139
141140
<script>
142141
*!*
143-
// form -> element
142+
// form -> elemen
144143
let login = form.login;
145144
146-
// element -> form
145+
// elemen -> form
147146
alert(login.form); // HTMLFormElement
148147
*/!*
149148
</script>
150149
```
151150
152-
## Form elements
151+
## Element Form
153152
154-
Let's talk about form controls.
153+
Mari bicara tentang kontrol form.
155154
156-
### input and textarea
155+
### input dan textarea
157156
158-
We can access their value as `input.value` (string) or `input.checked` (boolean) for checkboxes.
157+
Kita bisa akses nilai mereka dengan `input.value` (string) atau `input.checked` (boolean) untuk checkboxes.
159158
160-
Like this:
159+
Seperti ini:
161160
162161
```js
163162
input.value = "New value";
164163
textarea.value = "New text";
165164
166-
input.checked = true; // for a checkbox or radio button
165+
input.checked = true; // untuk checkbox atau radio button
167166
```
168167
169168
```warn header="Use `textarea.value`, not `textarea.innerHTML`"
170-
Please note that even though `<textarea>...</textarea>` holds its value as nested HTML, we should never use `textarea.innerHTML` to access it.
169+
Harap dicatat, meskipun `<textarea>...</textarea>` menyimpan nilainya sebagai HTML bersarang(nested), kita tidak boleh menggunakan `textarea.innerHTML` untuk mengaksesnya.
171170
172-
It stores only the HTML that was initially on the page, not the current value.
171+
itu hanya menyimpan HTML yang mulanya ada di halaman, bukan nilai saat ini.
173172
```
174173
175-
### select and option
174+
### select dan option
176175
177-
A `<select>` element has 3 important properties:
176+
Sebuah elemen `<select>` mempunyai 3 properti penting:
178177
179-
1. `select.options` -- the collection of `<option>` subelements,
180-
2. `select.value` -- the value of the currently selected `<option>`,
181-
3. `select.selectedIndex` -- the number of the currently selected `<option>`.
178+
1. `select.options` -- adalah koleksi dari `<option>` sub-element,
179+
2. `select.value` -- adalah nilai saat ini yang dipilih(selected) `<option>`,
180+
3. `select.selectedIndex` -- adalah nomor yang saat ini dipilih(selected) `<option>`.
182181
183-
They provide three different ways of setting a value for a `<select>`:
182+
Mereka menyediakan 3 cara berbeda untuk mengatur nilai pada `<select>`:
184183
185-
1. Find the corresponding `<option>` element and set `option.selected` to `true`.
186-
2. Set `select.value` to the value.
187-
3. Set `select.selectedIndex` to the number of the option.
184+
1. Mencari element `<option>` yang bersangkutan dan atur `option.selected` menjadi `true`.
185+
2. Atur `select.value`ke nilai.
186+
3. Atur `select.selectedIndex` ke nomor dari option.
188187
189-
The first way is the most obvious, but `(2)` and `(3)` are usually more convenient.
188+
Cara pertama adalah yang paling jelas, tetapi cara `(2)` dan `(3)` biasanya lebih nyaman.
190189
191-
Here is an example:
190+
Lihat contoh berikut:
192191
193192
```html run
194193
<select id="select">
@@ -198,18 +197,18 @@ Here is an example:
198197
</select>
199198
200199
<script>
201-
// all three lines do the same thing
200+
// semua 3 baris kode melakukan hal yang sama
202201
select.options[2].selected = true;
203202
select.selectedIndex = 2;
204203
select.value = 'banana';
205204
</script>
206205
```
207206
208-
Unlike most other controls, `<select>` allows to select multiple options at once if it has `multiple` attribute. Although such functionality is available, it is rarely used.
207+
Tidak seperti kontrol pada umumnya, `<select>` membolehkan memilih banyak opsi sekaligus jika memiliki atribut`multiple`.Fitur itu jarang digunakan.
209208
210-
In cases that you have to, then use the first way: add/remove the `selected` property from `<option>` subelements.
209+
Jika anda harus, maka gunakan cara pertama: tambah/hapus `selected`properti dari `<option>` sub-element.
211210
212-
We can get their collection as `select.options`, for instance:
211+
Kita bisa mendapatkan koleksinya sebagai `select.options`, misalnya:
213212
214213
```html run
215214
<select id="select" *!*multiple*/!*>
@@ -219,81 +218,82 @@ We can get their collection as `select.options`, for instance:
219218
</select>
220219
221220
<script>
222-
// get all selected values from multi-select
221+
// mendapatkan semua nilai selected dari multi-select
223222
let selected = Array.from(select.options)
224223
.filter(option => option.selected)
225224
.map(option => option.value);
226225
227-
alert(selected); // blues,rock
226+
alert(selected); // blues,rock
228227
</script>
229228
```
230229
231-
The full specification of the `<select>` element is available in the specification <https://html.spec.whatwg.org/multipage/forms.html#the-select-element>.
230+
Penjelasan lengkap dari elemen`<select>` tersedia di <https://html.spec.whatwg.org/multipage/forms.html#the-select-element>.
232231
233232
### new Option
234233
235-
This is rarely used on its own. But there's still an interesting thing.
234+
Ini jarang digunakan. Namun masih ada hal yang menarik.
236235
237-
In the [specification](https://html.spec.whatwg.org/multipage/forms.html#the-option-element) there's a nice short syntax to create `<option>` elements:
236+
Di dalam [penjelasan](https://html.spec.whatwg.org/multipage/forms.html#the-option-element) disana ada sintak pendek yang bagus untuk membuat elemen `<option>`:
238237
239238
```js
240239
option = new Option(text, value, defaultSelected, selected);
241240
```
242241
243242
Parameters:
244243
245-
- `text` -- the text inside the option,
246-
- `value` -- the option value,
247-
- `defaultSelected` -- if `true`, then `selected` HTML-attribute is created,
248-
- `selected` -- if `true`, then the option is selected.
244+
- `text` -- adalah teks didalam option,
245+
- `value` -- adalah nilai option,
246+
- `defaultSelected` -- jika `true`, maka `selected` HTML-attribute dibuat,
247+
- `selected` -- jika `true`, maka option nya *selected*.
249248
250-
There may be a small confusion about `defaultSelected` and `selected`. That's simple: `defaultSelected` sets HTML-attribute, that we can get using `option.getAttribute('selected')`. And `selected` - whether the option is selected or not, that's more important. Usually both values are either set to `true` or not set (same as `false`).
249+
Disana mungkin sedikit bingung tentang `defaultSelected` dan `selected`. That's simple: `defaultSelected` *set* HTML-attribute, dengan itu kita bisa dapat menggunakan `option.getAttribute('selected')`. Dan `selected` - baik opsi *selected* atau tidak, itu yang lebih penting. Biasanya kedua nilai baik di *set* ke `true` atau tidak di *set* (sama dengan `false`).
251250
252-
For instance:
251+
Misalnya:
253252
254253
```js
255254
let option = new Option("Text", "value");
256255
// creates <option value="value">Text</option>
257256
```
258257
259-
The same element selected:
258+
Elemen yang sama yang terpilih/*selected*:
260259
261260
```js
262261
let option = new Option("Text", "value", true, true);
263262
```
264263
265-
Option elements have properties:
264+
Elemen *option* memiliki properti:
266265
267266
`option.selected`
268-
: Is the option selected.
267+
: apakah option *selected*.
269268
270269
`option.index`
271-
: The number of the option among the others in its `<select>`.
270+
: Jumlah option diantara yang lain dalam elemen`<select>`.
272271
273272
`option.text`
274-
: Text content of the option (seen by the visitor).
273+
: Konten teks option(dilihat oleh pengunjung).
275274
276-
## References
275+
## Referensi
277276
278-
- Specification: <https://html.spec.whatwg.org/multipage/forms.html>.
277+
- Spesifikasi: <https://html.spec.whatwg.org/multipage/forms.html>.
279278
280-
## Summary
279+
## Kesimpulan
281280
282-
Form navigation:
281+
Navigasi Form:
283282
284283
`document.forms`
285-
: A form is available as `document.forms[name/index]`.
284+
: Sebuah form tersedia sebagai `document.forms[name/index]`.
286285
287-
`form.elements`
288-
: Form elements are available as `form.elements[name/index]`, or can use just `form[name/index]`. The `elements` property also works for `<fieldset>`.
286+
`form.elements`
287+
: Elemen form tersedia sebagai `form.elements[name/index]`, atau kita bisa gunakan `form[name/index]`. `elements` properti juga dapat berkerja dengan `<fieldset>`.
289288
290289
`element.form`
291-
: Elements reference their form in the `form` property.
290+
: Elemen referensi formulirnya dalam `form` properti.
292291
293-
Value is available as `input.value`, `textarea.value`, `select.value` etc, or `input.checked` for checkboxes and radio buttons.
292+
Nilai tersedia sebagai `input.value`, `textarea.value`, `select.value` dll, atau`input.checked` untuk *checkboxes* dan *radio buttons*.
294293
295-
For `<select>` we can also get the value by the index `select.selectedIndex` or through the options collection `select.options`.
294+
Untuk `<select>` kita juga bisa mendapatkan nilainya dengan index `select.selectedIndex` atau lewat koleksi option `select.options`.
296295
297-
These are the basics to start working with forms. We'll meet many examples further in the tutorial.
296+
Ini adalah dasar-dasar untuk mulai bekerja dengan form. Kita akan melihat banyak contoh lebih lanjut di tutorial.
298297
299-
In the next chapter we'll cover `focus` and `blur` events that may occur on any element, but are mostly handled on forms.
298+
Pada bab selanjutnya, kita akan membahas `focus` dan `blur` event yang mungkin terjadi pada elemen manapapun, tapi biasanya ditangani pada form.
299+
````

0 commit comments

Comments
 (0)