- Notifications
You must be signed in to change notification settings - Fork230
Forms: event and method submit#454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
joaquinelio merged 16 commits intojavascript-tutorial:masterfrompuntope:Forms-event-and-method-submitDec 14, 2020
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes fromall commits
Commits
Show all changes
16 commits Select commitHold shift + click to select a range
21fb24e
Forms: event and method submit
puntopeaf25299
Update task.md
puntope62f6bc5
Update solution.md
puntope7a8321a
Update index.html
puntopea1bf500
Update index.html
puntopeed8bf56
Update 2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/solution.md
puntopea3f2a94
Update 2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/solution.md
puntoped5f8910
Update 2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/solution.v…
puntopeb7350f2
Update 2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/task.md
puntope9164cba
Update 2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/task.md
puntope9e2559a
Update 2-ui/4-forms-controls/4-forms-submit/article.md
puntopea1e0e94
Update 2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/solution.md
puntope8132ed7
Update 2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/task.md
puntopef782995
Update 2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/task.md
puntope91715b7
Update 2-ui/4-forms-controls/4-forms-submit/article.md
puntope7cbe071
Update 2-ui/4-forms-controls/4-forms-submit/article.md
puntopeFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
8 changes: 4 additions & 4 deletions2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/solution.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
18 changes: 9 additions & 9 deletions2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/solution.view/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
6 changes: 3 additions & 3 deletions2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/source.view/index.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
28 changes: 14 additions & 14 deletions2-ui/4-forms-controls/4-forms-submit/1-modal-dialog/task.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
48 changes: 24 additions & 24 deletions2-ui/4-forms-controls/4-forms-submit/article.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
#Formularios: evento y método submit | ||
El evento`submit`se activa cuando el formlario es enviado, normalmente se utiliza para validar el formulario antes de ser enviado al servidor o bien para abortar el envío y procesarlo con JavaScript. | ||
El método `form.submit()`permite iniciar el envío del formulario medianteJavaScript.Podemos utilizarlo para crear y enviar nuestros propios formularios al servidor. | ||
Veamos más detalles sobre ellos. | ||
##Evento: submit | ||
Mayormente un formulario puede enviarse de dos maneras: | ||
1.La primera --Haciendo clicken`<input type="submit">`o en `<input type="image">`. | ||
2.La segunda --Pulsando la tecla`key:Enter`en un campo del formulario. | ||
Ambas acciones causan que el evento`submit`sea activado en el formulario. El handlerpuede comprobar los datos, y si hay errores, mostrarlos e invocar`event.preventDefault()`,entonces el formulario no será enviado al servidor. | ||
puntope marked this conversation as resolved. Show resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
En el formulario de abajo: | ||
1.Ve al campo tipo texto y pulsa la tecla `key:Enter`. | ||
2.Haz click en `<input type="submit">`. | ||
Ambas acciones muestran `alert`y el formulario no es enviado debido a la presencia de `return false`: | ||
```html autorun height=60 no-beautify | ||
<form onsubmit="alert('submit!');return false"> | ||
Primero: Enteren el campo de texto<input type="text" value="texto"><br> | ||
Segundo: Click en "submit": <input type="submit" value="Submit"> | ||
</form> | ||
``` | ||
````smart header="Relation between `submit` and `click`" | ||
Cuando un formulario es enviado utlizando `key:Enter`en un campo tipo texto, un evento`click`se genera en el `<input type="submit">` | ||
Muy curioso, dado quenohubo ningúnclicken absoluto. | ||
Aquí esta la demo: | ||
```html autorun height=60 | ||
<form onsubmit="return false"> | ||
<input type="text" size="30" value="Sitúa el cursor aquí y pulsa Enter"> | ||
<input type="submit" value="Submit" *!*onclick="alert('click')"*/!*> | ||
</form> | ||
``` | ||
```` | ||
##Método: submit | ||
Para enviar un formulario al servidor manualmente, podemos usar `form.submit()`. | ||
Entonces el evento`submit`no será generado. Se asume que si el programador llama`form.submit()`,entonces el scriptya realizó todo el procesamiento relacionado. | ||
A veces es usado para crear y enviar un formlario manualmente, como en este ejemplo: | ||
```js run | ||
let form = document.createElement('form'); | ||
@@ -58,7 +58,7 @@ form.method = 'GET'; | ||
form.innerHTML = '<input name="q" value="test">'; | ||
//el formulario debe estar en el documentpara poder enviarlo | ||
document.body.append(form); | ||
form.submit(); | ||
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.