Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d1e7a53

Browse files
committed
docs(form): add docs about form submission
1 parent 2090136 commit d1e7a53

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

src/widget/form.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,35 @@
1919
* element nesting.
2020
*
2121
*
22+
* # Submitting a form and preventing default action
23+
*
24+
* Since the role of forms in client-side Angular applications is different than in old-school
25+
* roundtrip apps, it is desirable for the browser not to translate the form submission into a full
26+
* page reload that sends the data to the server. Instead some javascript logic should be triggered
27+
* to handle the form submission in application specific way.
28+
*
29+
* For this reason, Angular prevents the default action (form submission to the server) unless the
30+
* `<form>` element has an `action` attribute specified.
31+
*
32+
* You can use one of the following two ways to specify what javascript method should be called when
33+
* a form is submitted:
34+
*
35+
* - ng:submit on the form element (add link to ng:submit)
36+
* - ng:click on the first button or input field of type submit (input[type=submit])
37+
*
38+
* To prevent double execution of the handler, use only one of ng:submit or ng:click. This is
39+
* because of the following form submission rules coming from the html spec:
40+
*
41+
* - If a form has only one input field then hitting enter in this field triggers form submit
42+
* (`ng:submit`)
43+
* - if a form has has 2+ input fields and no buttons or input[type=submit] then hitting enter
44+
* doesn't trigger submit
45+
* - if a form has one or more input fields and one or more buttons or input[type=submit] then
46+
* hitting enter in any of the input fields will trigger the click handler on the *first* button or
47+
* input[type=submit] (`ng:click`) *and* a submit handler on the enclosing form (`ng:submit`)
48+
*
49+
* @param {string=} name Name of the form.
50+
*
2251
* @example
2352
<doc:example>
2453
<doc:source>

0 commit comments

Comments
 (0)