Problem/Motivation
Port the ajax add more button example to drupal 8.
add more image
The above is the image which describes about the ajax example which was in drupal 7

Proposed resolution

Port the ajax add more button example to d8 .

Testing Instructions

  1. Enable example and Form API Example module .
  2. After enabling you will find a sub menu named Ajax add more example
  3. Enter the value in textbox and click on add one more textbox is added to the form
  4. And on click of remove button it removes the recently added textbox.
  5. On click of submit it displays all values entered in textbox.
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Shreya Shetty created an issue. See original summary.

Shreya Shetty’s picture

Status: Active » Needs review
FileSize
4.3 KB

Hi I have created a patch for the feature requested . But for now i have included this under form examples menu . We can create an independent menu of ajax examples wherein we can include more examples on ajax.

Status: Needs review » Needs work

The last submitted patch, 2: add_more-2720361-2.patch, failed testing.

Shreya Shetty’s picture

Status: Needs work » Needs review
navneet0693’s picture

@Shreya: We have something going on here: #2102639: Port ajax_example module to Drupal 8 Does this issue needs a summary update ? For porting refer: https://www.drupal.org/node/1880976 Please, correct me if I am wrong in understanding this issue :P.

navneet0693’s picture

Status: Needs review » Needs work
Shreya Shetty’s picture

Yes .. in drupal 7 we had many examples on ajax..The issue which u mentioned is of other ajax example in d7.And this ajax example is different from the issue u have mentioned.

navneet0693’s picture

@Shreya: Can we update summary for more explanation ?

Shreya Shetty’s picture

Sure...we can.

Shreya Shetty’s picture

Shreya Shetty’s picture

Issue summary: View changes
Shreya Shetty’s picture

Status: Needs work » Needs review
FileSize
4.29 KB
Riya Roy’s picture

Status: Needs review » Reviewed & tested by the community

I have tested the patch it works fine . Now its up to the maintainers to include this ajax example in examples module

Torenware’s picture

Status: Reviewed & tested by the community » Needs work
  1. +++ b/fapi_example/fapi_example.links.menu.yml
    @@ -45,3 +45,9 @@ fapi_example.build_demo:
    +  description: A form to demonstrate use of AJAX.
    

    This should be different from the regular AJAX example.

  2. +++ b/fapi_example/fapi_example.links.menu.yml
    @@ -45,3 +45,9 @@ fapi_example.build_demo:
    \ No newline at end of file
    

    You need a new line at end of file.

  3. +++ b/fapi_example/fapi_example.routing.yml
    @@ -81,3 +81,11 @@ fapi_example.build_demo:
    \ No newline at end of file
    

    Again, no NL at EOL.

  4. +++ b/fapi_example/src/Form/AjaxAddMore.php
    @@ -0,0 +1,98 @@
    \ No newline at end of file
    

    Again, you need a NL alone in the last line.

In addition, if you notice, the controller lists the examples for the Form API Example Module. You need to add yours to this.

It might even be better just to combine these two AJAX examples into a single form, which is easy enough to do. I'm curious what other folks might think about this.

Torenware’s picture

Also: a lot of issues with indentation and comment structure. Here, you may want to install phpcs, a tool we very often use to check files for indentation and other style errors. You can find some instructions here: #2176147: [meta] Coding standards review for D8 Examples.

It will take you a bit to install the tool, but I strongly recommend it. It will make it very easy for you to write "core ready" code, since the tool finds all kinds of things you might not know about, or even see.

Once you've run the tool and fixed the problems you find, I'll give the issue another look.

Thanks for working on this; we're not too far from being done here.

Shreya Shetty’s picture

Assigned: Unassigned » Shreya Shetty
Shreya Shetty’s picture

Status: Needs work » Needs review
FileSize
5.95 KB

Thanks a ton @Rob for the guidance . I have done as per suggestion given by you . Since we have only two examples based on ajax for now let it be under form example . Later on if we have more ajax examples we can think of combining all those to a single form . I would like to hear from the community what they think on it . Please review the patch .

Riya Roy’s picture

Status: Needs review » Reviewed & tested by the community

Yes everything looks fine . Good to go .

Torenware’s picture

+++ b/fapi_example/src/Controller/Page.php
@@ -30,6 +30,7 @@ class Page extends ControllerBase {
+         Link::createFromRoute($this->t('Add-more button'), 'fapi_example.ajax_addmore'),

One trivial error: this line has an extra space of indent (9 instead of 8). I'll fix this before I check this in.

Torenware’s picture

Status: Reviewed & tested by the community » Fixed

Thanks for your work on this. The extra space has been removed, and I've checked this in.

Shreya Shetty’s picture

Status: Fixed » Closed (fixed)

Thanks a lot @Rob for fixing and committing this . Will look forward to give more patches.