🚀 Creating an AJAX Form into our Drupal 8 custom module programmatically

Поділитися
Вставка
  • Опубліковано 19 вер 2024
  • In this video, we will extend a bit the module that we started in the previous video (goo.gl/RntX9j). We will basically create an AJAX version of the same form.
    If you liked this video, please also have a look at my new corse about Drupal 8 module development here (with 50% discount):
    goo.gl/LPyeDw
    The code of this AJAX form could be found here:
    github.com/dru...

КОМЕНТАРІ • 16

  • @andresanxoperezsanchez6665
    @andresanxoperezsanchez6665 4 роки тому

    Thank you! this video is very useful

  • @naderat
    @naderat 2 роки тому

    Thank you so much. Your videos are very helpful :-)

  • @oleksandrsyvyi6242
    @oleksandrsyvyi6242 6 років тому +2

    Hi Nikolay, what is the reason to use $this->t(Calculate) instead t(Calculate)?
    And what is reason to use &$form instead $form?

    • @Drupal-up
      @Drupal-up  6 років тому +1

      Hi Александр,
      great question again!
      We are supposed to use $this->t() in order to use the services that are injected for us just by extending the FormBase class (api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21FormBase.php/class/FormBase/8.2.x). This way the whole quality of the code is better and testable. In a simple example - there is no difference, but in the general case, it is a good practice to either extend a base class in order to have some services and use them or inject the services that you need and use them. Just using t() is possible because of Drupal 7 legacy, but is a bad practice for Drupal 8 projects.
      Passing by reference is kind of a requirement for almost all Drupal form functions, except buildForm. That's I think because we have the hook_form_alter hook in Drupal and if you want to alter the form at some state by another module of yours - it should be passed by reference because in hook_form_alter we are of course not returning anything.
      here is the documentation of hook_form_alter:
      api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Form%21form.api.php/function/hook_form_alter/8.5.x
      here is your question, answered by someone on drupal.org:
      www.drupal.org/forum/support/module-development-and-code-questions/2012-12-25/why-we-pass-arguments-with-reference
      Cheers and have a nice day!
      Nikolay

    • @oleksandrsyvyi6242
      @oleksandrsyvyi6242 6 років тому

      Drupal Up - Drupal 8 Video Tutorials thanks for the fact that my questions are interesting for you and you give answers for it.
      Can you please discover the in you video: services, dependency injections and event subscribers ??

  • @Soumya21st
    @Soumya21st 6 років тому +1

    Great tutorials. Keep it up!!!
    I have two questions regarding this
    1)The message is shown in result_message or my_top_message. Also I want to show the message beside the second text box and not on top
    2)How can I show the result for mouseout/mouseleave option and not by clicking a button?

    • @Drupal-up
      @Drupal-up  6 років тому +1

      Hi Soumya Banerjee,
      If you check the code here github.com/drupal-up/drupalup_simple_form/blob/master/src/Form/SimpleAjaxForm.php
      You will see that setMessage() method with the help of HtmlCommand is setting the result in an element with class "result_message" - it could be basically any element on the page it is not restricted to the elements that we create.
      For your second question, you can use something like this and then implement the callback function as shown in this video
      $form['textfieldname'] = array(
      '#type' => 'textfield',
      '#title' => t('Your field'),
      '#ajax' => [
      'callback' => '::fetchApiData',
      'event' => 'change',
      'prevent' => 'click',
      ],
      );
      have a look at the docu here www.drupal.org/docs/8/api/javascript-api/ajax-forms
      In the future I am planning to create a video also about other similar problems.
      Cheers!

    • @Soumya21st
      @Soumya21st 6 років тому +1

      Superb!!! Thanks a ton

  • @shivalik_chopra
    @shivalik_chopra 5 років тому

    I want to insert and edit values of form. Saving values in db

  • @hamzaliaqat952
    @hamzaliaqat952 4 роки тому +1

    make a video to insert images into database with custom form

  • @monishanarayan3537
    @monishanarayan3537 4 роки тому

    It shows me page not found error while redirecting through the path name

  • @webdevelopment5076
    @webdevelopment5076 5 років тому +1

    i need ajax dropdown pls share

  • @epi_sto_letes
    @epi_sto_letes 5 років тому

    supporting AJAX in D8 seems to have gotten more complicated.

  • @cooliofv
    @cooliofv 6 років тому +1

    А по русски нельзя? Американе, блин.

    • @Drupal-up
      @Drupal-up  6 років тому +1

      Hi Алексей,
      yes, sorry but I don't speak Russian ... the end code of this video you still may find here though -> github.com/drupal-up/drupalup_simple_form/blob/master/src/Form/SimpleAjaxForm.php
      Also if you ask any question in Russain - I will try to answer it.
      Cheers and have a nice day!

    • @kirillkirillovich7316
      @kirillkirillovich7316 4 роки тому

      @@Drupal-up можливо українською мовою буде ?