Skip to content

Commit f084555

Browse files
committed
minor #19576 [Forms] Use regular JavaScript functions in the examples (jennevdmeer)
This PR was submitted for the 7.0 branch but it was squashed and merged into the 6.4 branch instead. Discussion ---------- [Forms] Use regular JavaScript functions in the examples There is no real point to use `const` for functions. While it surely is an opinion, the arrow syntax should only be used for anonymous functions and it seems more confusing for newer people. * To me and I would assume a new user `function (...) {` is instantly more clearer that we are working with a function instead of a variable * Function has no name during debugging when using arrow syntax * Its not shorter `function foo(e) {` vs `const foo = (e) => {` * Hoisting is weird, specially for newer people (https://stackoverflow.com/a/33040926) I also changed the introduction line to the delete button part to detail what the user is going to do in following code block which seemed a little unclear to me personally. If the writing is not ok, please change it. Commits ------- 67eff99 [Forms] Use regular JavaScript functions in the examples
2 parents 577ef2d + 67eff99 commit f084555

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

form/form_collections.rst

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ you'll replace with a unique, incrementing number (e.g. ``task[tags][3][name]``)
314314

315315
.. code-block:: javascript
316316
317-
const addFormToCollection = (e) => {
317+
function addFormToCollection(e) {
318318
const collectionHolder = document.querySelector('.' + e.currentTarget.dataset.collectionHolderClass);
319319
320320
const item = document.createElement('li');
@@ -579,7 +579,8 @@ on the server. In order for this to work in an HTML form, you must remove
579579
the DOM element for the collection item to be removed, before submitting
580580
the form.
581581

582-
First, add a "delete this tag" link to each tag form:
582+
In our JavaScript, we first need add a "delete" button to each existing tag on the page.
583+
Then, we append the "add delete button" method in the function that adds the new tags.
583584

584585
.. code-block:: javascript
585586
@@ -591,7 +592,7 @@ First, add a "delete this tag" link to each tag form:
591592
592593
// ... the rest of the block from above
593594
594-
const addFormToCollection = (e) => {
595+
function addFormToCollection(e) {
595596
// ...
596597
597598
// add a delete link to the new form
@@ -602,7 +603,7 @@ The ``addTagFormDeleteLink()`` function will look something like this:
602603

603604
.. code-block:: javascript
604605
605-
const addTagFormDeleteLink = (item) => {
606+
function addTagFormDeleteLink(item) {
606607
const removeFormButton = document.createElement('button');
607608
removeFormButton.innerText = 'Delete this tag';
608609

0 commit comments

Comments
 (0)