0

We have one custom extension which try to add additional field on scheduled job New/Edit screen using hook.

    function jobextra_civicrm_buildForm($formName, &$form) {
      if ($formName == 'CRM_Admin_Form_Job') {
        $form->add('datepicker', 'job_date_time_start', ts('Date & Time Start'), NULL, FALSE, ['minDate' => date('Y-m-d')]);
        $form->add('datepicker', 'job_date_time_end', ts('Date & Time End'), NULL, FALSE, ['minDate' => date('Y-m-d')]);
        // there are other non date related field
      }
    }

and supporting extra.tpl file templates/CRM/Admin/Page/Job.extra.tpl

{literal}
<script type="text/javascript">
    CRM.$(document).ready(function() {
        CRM.$('.crm-job-form-block-name_job_date_time_end').insertAfter('.crm-job-form-block-run_frequency');
        CRM.$('.crm-job-form-block-name_job_date_time_start').insertAfter('.crm-job-form-block-run_frequency');
         // other fields are inserted...
    });

</script>
{/literal}
<table style="display:none;">
    <tr class="crm-job-form-block-name_job_date_time_start" style="">
        <td class="label">{$form.job_date_time_start.label}</td>
        <td>{$form.job_date_time_start.html}
        </td>
    </tr>
    <tr class="crm-job-form-block-name_job_date_time_end" style="">
        <td class="label">{$form.job_date_time_end.label}</td>
        <td>{$form.job_date_time_end.html}</td>
    </tr>
</table>

Date field is not rendering correctly, instead of showing date picker field and time field, i am just seeing simple textfield.

If i put these 2 field into core templates/CRM/Admin/Form/Job.tpl, both field rendered correctly.

Since this is in extra.tpl , tpl file load outside crm-container, and then we moving these field using jQuery into right position inside crm-container.

that may be issue?.

1 Answer 1

2

You need to initialize datepicker field

$('input[name="job_date_time_end"]').datepicker();

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.