commit ee7b04ea44f1f1c4682ba4e3882fc56b932af1ca
Author: Jonathan Araña Cruz <jonhattan@faita.net>
Date:   Sat Feb 9 11:54:01 2013 +0100

    Disable field options once it has data, and only validate hours if requested

diff --git a/office_hours.module b/office_hours.module
index a2ab8aa..4fd3f2e 100644
--- a/office_hours.module
+++ b/office_hours.module
@@ -133,6 +133,7 @@ function office_hours_field_settings_form($field, $instance, $has_data) {
     '#default_value' => $settings['hoursformat'],
     '#required' => FALSE,
     '#description' => t('Format of the clock. IMPORTANT NOTE: if you do not select "Multiple values", you can enter only one day.'),
+    '#disabled' => $has_data,
   );
   $form['granularity'] = array(
     '#type' => 'select',
@@ -141,6 +142,7 @@ function office_hours_field_settings_form($field, $instance, $has_data) {
     '#default_value' => $settings['granularity'],
     '#required' => FALSE,
     '#description' => t('Restrict the input to fixed fractions of an hour.'),
+    '#disabled' => $has_data,
   );
   $form['addhrs'] = array(
     '#type' => 'checkbox',
@@ -155,6 +157,7 @@ function office_hours_field_settings_form($field, $instance, $has_data) {
     '#required' => FALSE,
     '#default_value' => $settings['valhrs'],
     '#description' => t('Assure that endhours are later then starthours. Please note that this will work as long as the opening hours are not through midnight.'),
+    '#disabled' => $has_data,
   );
   $hours = _office_hours_show_ampm(date_hours('H'));
   $form['limitstart'] = array(
@@ -163,6 +166,7 @@ function office_hours_field_settings_form($field, $instance, $has_data) {
     '#description' => t('Restrict the hours available - select options will start from this hour.'),
     '#default_value' => $settings['limitstart'],
     '#options' => $hours,
+    '#disabled' => $has_data,
   );
   $form['limitend'] = array(
     '#type' => 'select',
@@ -170,19 +174,21 @@ function office_hours_field_settings_form($field, $instance, $has_data) {
     '#description' => t('Restrict the hours available - select options will end at this hour.'),
     '#default_value' => $settings['limitend'],
     '#options' => $hours,
+    '#disabled' => $has_data,
   );
 
   return $form;
 }
 
 /**
- * Implements the #element_validate callback for myfield_field_settings_form().
+ * Implements the #element_validate callback for office_hours_field_settings_form().
+ *
  * Verifies the office hours limits.
  * "Please note that this will work as long as the opening hours are not through midnight."
  */
 function _office_hours_field_settings_form_validate($element, &$form_state) {
-  if ($element['limitstart']['#value'] > $element['limitend']['#value']) {
-    form_error($element['limitstart'], t('%start is later then %end.', array('%start' => $element['limitstart']['#title'], '%end' => $element['limitend']['#title'] )));
+  if (($element['valhrs']['#value']) && ($element['limitstart']['#value'] > $element['limitend']['#value'])) {
+    form_error($element['limitstart'], t('%start is later than %end.', array('%start' => $element['limitstart']['#title'], '%end' => $element['limitend']['#title'] )));
   }
 }
 
