Button act as submit button in form API I have a button element in form builder as follows 

$form['fieldset']['add_new_event_btn'] = array(
  '#value' =&gt; t('Add new event trigger'),
  '#type' =&gt; 'button',
  '#attributes' =&gt; array(
    'style' =&gt; 'margin-top:20px;width:200px;margin-right:275px;float:right',
  ),
  '#ajax' =&gt; array(
    // Function to call when event on form element triggered.
    'callback' =&gt; '::enable_event_trigger',
    // Effect when replacing content. Options: 'none' (default), 'slide', 'fade'.
    'effect' =&gt; 'fade',
    // Javascript event to trigger Ajax. Currently for: 'onchange'.
    'event' =&gt; 'click',
    'progress' =&gt; array(
      // Graphic shown to indicate ajax. Options: 'throbber' (default), 'bar'.
      'type' =&gt; 'throbber',
      // Message to show along progress graphic. Default: 'Please wait...'.
      'message' =&gt; 'loading',
    ),
  ),
);


But this button is act as the submit button , and there for the validation for other elements works and shows the error message on the next reload when i leave the page as it is, How can i rectify this problem ??
As mentioned in the comments, this is not supported yet but it might at some point: https://www.drupal.org/project/drupal/issues/1671190

What you can do is return false in the onclick event. For example:

$form[button] = array(
  '#type' =&gt; 'button',
  '#name' =&gt; 'button',
  '#value' =&gt; "Do some JS",
  "#attributes" =&gt; array(
    "onclick" =&gt; "doJs(); return false;",
  ),
);