diff --git a/appointment_calendar.module b/appointment_calendar.module
index 2f58de8..223c772 100644
--- a/appointment_calendar.module
+++ b/appointment_calendar.module
@@ -1,6 +1,5 @@
 <?php
 
-use Drupal\Core\Datetime\DrupalDateTime;
 use Drupal\Core\Form\FormStateInterface;
 
 /**
@@ -8,15 +7,20 @@ use Drupal\Core\Form\FormStateInterface;
  */
 function appointment_calendar_form_alter(&$form, FormStateInterface $form_state, $form_id) {
   if ($form_id == 'node_appointment_calendar_form' || $form_id == 'node_appointment_calendar_edit_form') {
-    $selected_date = strtotime(date('Y-m-d', $form['field_appointment_date']['widget'][0]['value']['#default_value']->getTimestamp()));
+    if (isset($form_state)) {
+      $selected_date = strtotime(date('Y-m-d', $form_state->getValue('field_appointment_date')[0]['value']->getTimestamp()));
+    }
+    else {
+      $selected_date = strtotime(date('Y-m-d', $form['field_appointment_date']['widget'][0]['value']['#default_value']->getTimestamp()));
+    }
     $current_path = \Drupal::service('path.current')->getPath();
     $path_args = explode('/', $current_path);
     // Check for edit page.
     if ($path_args[1] == 'node' && is_numeric($path_args[2])) {
       $nid = $path_args[2];
-      $default_value = appointment_calendar_slot_value($path_args[2]);
+      $default_value = appointment_calendar_slot_value($nid);
     }
-    $options = array();
+    $options = [];
     // Get slot values.
     $slot_result = get_slot_values($selected_date);
     foreach ((array) json_decode($slot_result) as $key => $value) {
@@ -31,7 +35,7 @@ function appointment_calendar_form_alter(&$form, FormStateInterface $form_state,
     ];
     $form['appointment_fill'] = [
       '#type' => 'button',
-      '#value' => 'Check Slot',
+      '#value' => t('Check Slot'),
       '#weight' => $form['field_appointment_date']['#weight'],
       '#ajax' => array(
         'callback' => 'appointment_calendar_appointment_calendar_timeslot_callback_form',
