10000 Update form_collections.rst · symfony/symfony-docs@bd4abba · GitHub
[go: up one dir, main page]

Skip to content

Commit bd4abba

Browse files
committed
Update form_collections.rst
The variable collectionHolder must be assigned inside the jQuery ready function, but must be declared outside, since it is used also in other functions. I have put back the '$' in front of names of variables having jQuery objects as values and for uniformity, also added it to collectionHolder.
1 parent de2aac2 commit bd4abba

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

cookbook/form/form_collections.rst

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -358,27 +358,29 @@ will be show next):
358358

359359
.. code-block:: javascript
360360
361+
var $collectionHolder;
362+
361363
// setup an "add a tag" link
362-
var addTagLink = $('<a href="#" class="add_tag_link">Add a tag</a>');
363-
var newLinkLi = $('<li></li>').append(addTagLink);
364+
var $ 10000 addTagLink = $('<a href="#" class="add_tag_link">Add a tag</a>');
365+
var $newLinkLi = $('<li></li>').append($addTagLink);
364366
365367
jQuery(document).ready(function() {
366368
// Get the ul that holds the collection of tags
367-
var collectionHolder = $('ul.tags');
369+
$collectionHolder = $('ul.tags');
368370
369371
// add the "add a tag" anchor and li to the tags ul
370-
collectionHolder.append(newLinkLi);
372+
$collectionHolder.append($newLinkLi);
371373
372374
// count the current form inputs we have (e.g. 2), use that as the new
373375
// index when inserting a new item (e.g. 2)
374-
collectionHolder.data('index', collectionHolder.find(':input').length);
376+
$collectionHolder.data('index', $collectionHolder.find(':input').length);
375377
376-
addTagLink.on('click', function(e) {
378+
$addTagLink.on('click', function(e) {
377379
// prevent the link from creating a "#" on the URL
378380
e.preventDefault();
379381
380382
// add a new tag form (see next code block)
381-
addTagForm(collectionHolder, newLinkLi);
383+
addTagForm($collectionHolder, $newLinkLi);
382384
});
383385
});
384386
@@ -393,23 +395,23 @@ one example:
393395

394396
.. code-block:: javascript
395397
396-
function addTagForm(collectionHolder, newLinkLi) {
398+
function addTagForm($collectionHolder, $newLinkLi) {
397399
// Get the data-prototype explained earlier
398-
var prototype = collectionHolder.data('prototype');
400+
var prototype = $collectionHolder.data('prototype');
399401
400402
// get the new index
401-
var index = collectionHolder.data('index');
403+
var index = $collectionHolder.data('index');
402404
403405
// Replace '$$name$$' in the prototype's HTML to
404406
// instead be a number based on how many items we have
405407
var newForm = prototype.replace(/\$\$name\$\$/g, index);
406408
407409
// increase the index with one for the next item
408-
collectionHolder.data('index', index + 1);
410+
$collectionHolder.data('index', index + 1);
409411
410412
// Display the form in the page in an li, before the "Add a tag" link li
411-
var newFormLi = $('<li></li>').append(newForm);
412-
newLinkLi.before(newFormLi);
413+
var $newFormLi = $('<li></li>').append($newForm);
414+
$newLinkLi.before($newFormLi);
413415
}
414416
415417
.. note::

0 commit comments

Comments
 (0)
0