Skip to content

[Forms] Use regular JavaScript functions in the examples #19576

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions form/form_collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ you'll replace with a unique, incrementing number (e.g. ``task[tags][3][name]``)

.. code-block:: javascript

const addFormToCollection = (e) => {
function addFormToCollection(e) {
const collectionHolder = document.querySelector('.' + e.currentTarget.dataset.collectionHolderClass);

const item = document.createElement('li');
Expand Down Expand Up @@ -579,7 +579,8 @@ on the server. In order for this to work in an HTML form, you must remove
the DOM element for the collection item to be removed, before submitting
the form.

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

.. code-block:: javascript

Expand All @@ -591,7 +592,7 @@ First, add a "delete this tag" link to each tag form:

// ... the rest of the block from above

const addFormToCollection = (e) => {
function addFormToCollection(e) {
// ...

// add a delete link to the new form
Expand All @@ -602,7 +603,7 @@ The ``addTagFormDeleteLink()`` function will look something like this:

.. code-block:: javascript

const addTagFormDeleteLink = (item) => {
function addTagFormDeleteLink(item) {
const removeFormButton = document.createElement('button');
removeFormButton.innerText = 'Delete this tag';

Expand Down