0

Is there any way to add time range input fields in a form, for example using code similar to the following one?

$form['notification_hours'] = array(
  '#type' => 'time_range', // type time_range doesn't work
  '#title' => $this->t('Notification hours:'),
  '#default_value' => $config->get('ecc_general.notification_hours'),
  '#description' => $this->t('what are the hours that messages should not be sent?'),
);

I have tried the Time Range and and Time Field modules. I'm able to add the time range field, but I failed to programmatically create it.

2
  • Maybe the Duration Field module (dgo.to/duration_field)
    – Jaypan
    Commented Jul 6, 2019 at 15:19
  • Tried it, wasn't the one that I want :(
    – Mohandes
    Commented Jul 7, 2019 at 11:30

1 Answer 1

0

Haven't tested this but if you install time field module you then could do this to simulate a range:

$form['from'] = [
  '#type' => 'time',
  '#title' => 'from',
];
$form['to'] = [
  '#type' => 'time',
  '#title' => 'to',
];
1
  • Thanks for answer, but this creates two separate input fields, by time range field I mean both from and to in one input filed.
    – Mohandes
    Commented Jul 6, 2019 at 13:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.