Edit a node using AJAX I'm loading the edit node form in a block and I want to use Ajax to save the node.

class MyBLockNameBlock extends BlockBase{

  public function build() {
    //I find the $nid i want to display

    $entity = Node::load($nid);
    $form = \Drupal::service('entity.form_builder')-&gt;getForm($entity, 'default');

    $form['actions']['#type'] = 'actions';
    $form['actions']['submit'] = [
      '#type' =&gt; 'submit',
      '#value' =&gt; $this-&gt;t('Submit'),
      '#ajax' =&gt; [
      'wrapper' =&gt; $wrapper_id,
      'callback' =&gt; '::ajaxCallback',
     ],
   ];

   $block['form'] = $form;
   $block['#markup'] = $this-&gt;t('&lt;h3&gt;Project Plan&lt;/h3&gt;');
   return $block;

  }

  public function validateForm(array &amp;$form, FormStateInterface $form_state)
  {
    if($form_state-&gt;hasAnyErrors()){
      return $form;
    }
  }

  public function ajaxCallback(array &amp;$form, FormStateInterface $form_state)
  {
     return $form;
  }
}


But it doesn't work.
If I change the $form['actions']['submit'] to 

$form['actions']['submit'] = [
  '#type' =&gt; 'submit',
  '#value' =&gt; $this-&gt;t('Submit'),
  '#attributes'   =&gt;array('class' =&gt; array('btn btn-info use-ajax-submit')),
  '#ajax' =&gt; [
    'wrapper' =&gt; $wrapper_id,
    'callback' =&gt; '::ajaxCallback',
  ],
];


The Ajax works but it doesn't validate the form.
Should I create the validation by myself for each field?

Also I tried ajax_form_entity module but even if the ajax works, reloads the form, doesn't clear the fields after submission and still doesn't validate.

Also I need an extra handler when the user clicks the submit button in order to update a field from an other form.

Any idea?
You cannot add elements to the form outside of the form definition. You are adding your form elements in your block class, which is why it's not working as you expect. If you want to alter the entity form, you'll need to use hook_form_alter() and add your ajax there.