Drupal 8 : Programatically Enabling/Disabling Javascript Local storage for Drupal 8 Forms

Using the help of JavaScript we can able to store the values at browser(local storage). In Drupal 8 core "form.js" file help to maintain form local storage. This can be achieved by sitting boolean value to form key 'data-user-info-from-browser'. The below sample code show how to form variable to save in local storage.

Syntax:
To enable Local storage: 

$form['#attached']['library'][] = 'core/drupal.form';
$form['#attributes']['data-user-info-from-browser'] = TRUE;

To Disbale Local Storage: 

$form['#attached']['library'][] = 'core/drupal.form';
$form['#attributes']['data-user-info-from-browser'] = FALSE;

Example: 

function local_storage_form($form, $form_state) {
    .....
    .....
    $form['fname'] = array(
      "#type" => "textfield",
      "#title" => "First Name :",
      "#weight" => 10,
    );
    $form['lname'] = array(
      "#type" => "textfield",
      "#title" => "Last Name :",
      "#weight" => 11,
    );
    $form['mail'] = array(
      "#type" => "email",
      "#title" => "Mail :",
      "#weight" => 12,
    );
    .....
    .....
 
    $form['#attached']['library'][] = 'core/drupal.form';
    $form['#attributes']['data-user-info-from-browser'] = TRUE;
    return $form;
}
 
<strong>Local Storage to be like:</strong>
Drupal.fname : Arunkumar
Drupal.fname : Kuppuswamy
Drupal.mail : arunkumar1.akk@gmail.com
Category: