我真的很想知道如何在symfony 4中为医院管理建立预订表格。用户选择一个医生,一个日期,然后在此页面中显示该医生在该日期的可用性时间。谢谢!
好吧@ADyson这是我的ReservationFormType:公共功能buildForm(FormBuilderInterface $ builder,数组$ options){$建设者->添加('medicalStaff',EntityType :: class,['class'=> MedicalStaff :: class,'标签'=> false,'required'=> true])->添加(“ invoiceDate”,DateType :: class,['widget'=>'single_text','输入'=>'日期时间',])->添加('availableTimes',ChoiceType :: class)-> addEventListener(FormEvents :: PRE_SUBMIT,函数(FormEvent $ event){
// get the form from the event
$form = $event->getForm();
$formOptions = $form->getConfig()->getOptions();
//helpers
//$availableTimeHandler = $formOptions['availableTimes'];
// get the form data, that got submitted by the user with this request / event
$data = $event->getData();
//get date
$preferredDate = $data['invoiceDate'];
// get the availableTimes element and its options
$fieldConfig = $form->get('availableTimes')->getConfig();
$fieldOptions = $fieldConfig->getOptions();
$times =
[
['time' => '10:00', 'disabled' => false],
['time' => '11:00', 'disabled' => true],
['time' => '12:00', 'disabled' => true],
];
$choices = [];
foreach ($times as $time) {
$choices[] = [$time['time'] => $time['time']];
}
//update choices
$form->add('availableTimes', ChoiceType::class,
array_replace(
$fieldOptions, [
'choices' => $choices
]
)
);
});
}
然后这是我实现给Reservation.twig.html的功能
<script>
var path = "{{ path('app_profile_main') }}";
$('.reservation-date').datepicker({
format:'yyyy.MM.dd',
});
$(".reservation-hour").change(function () {
$.ajax({
type: "GET",
dataType: "json",
url: path,
data: {},
success: function (data) {
$(".reservation-times").empty();
$.each(data, function (key, value) {
//popullimi me
let disabled = (value.disabled === true ? "disabled" : '');
$(".reservation-times").append('<option ' + disabled + ' value=' + value.time + '>' + value.time + '</option>');
})
}
,
error: function (error) {
console.log(error);
}
});
})
</script>
[我只想要,当单击日期以显示表单中的可用小时时。谢谢!