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

แชร์
ฝัง
  • เผยแพร่เมื่อ 9 พ.ย. 2024

ความคิดเห็น • 16

  • @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

  • @andresanxoperezsanchez6665
    @andresanxoperezsanchez6665 4 ปีที่แล้ว

    Thank you! this video is very useful

  • @hamzaliaqat952
    @hamzaliaqat952 4 ปีที่แล้ว +1

    make a video to insert images into database with custom form

  • @webdevelopment5076
    @webdevelopment5076 5 ปีที่แล้ว +1

    i need ajax dropdown pls share

  • @shivalik_chopra
    @shivalik_chopra 5 ปีที่แล้ว

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

  • @monishanarayan3537
    @monishanarayan3537 4 ปีที่แล้ว

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

  • @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 можливо українською мовою буде ?