我需要在@if条件中使用old()变量值。当我打开UPDATE表单时,我看到正确的值。但我不知道为什么,当我在条件中使用old()时,值为NULL。此表单在fullcalendar中使用。其实我用ajax。
表格更新:
<!-- FORM per aggiornare eventi -->
{!!Form::open(['route'=>['events.update',1], 'method'=>'PUT', 'id'=>'updatemodal'])!!}
<div class="form-group">
{!! Form::label('tipologia_evento_id', 'Tipo evento') !!}
<select id="tipologia_evento_id" name="tipologia_evento_id" class="form-control" disabled>
@foreach(DB::table('tipologie_eventi')->get() as $tipologia)
<option
@if(old('_tipologia_evento_id') == $tipologia->id)
selected="selected"
@endif
value="{{$tipologia->id}}">{{$tipologia->nome}}</option>
@endforeach
</select>
</div>
@if(!in_array(old('_tipologia_evento_id'),array(1,2)))
<div class="modal-footer">
<meta name="csrf-token" content="{{ csrf_token() }}">
<a id="delete" data-href="{{ url('events') }}" data-id="" class="btn btn-danger">Elimina</a>
<button id="aggiornaBtn" type="submit" class="btn btn-success" disabled="disabled">Aggiorna</button>
</div>
@endif
{!! Form::close() !!}
AJAX代码:
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,listDay'
},
navLinks: true, // can click day/week names to navigate views
editable: false,
selectable: true,
selectHelper: true,
select: function(start, end){
start = moment(start.format());
end = moment(end.format());
$('#date_start').val(start.format('DD.MM.YYYY'));
$('#date_end').val(end.format('DD.MM.YYYY HH:mm'));
$('#responsive-modal').modal('show');
},
events: BASEURL + '/events',
eventClick: function(event, jsEvent, view){
var date_start = $.fullCalendar.moment(event.start).format('DD.MM.YYYY');
var time_start = $.fullCalendar.moment(event.start).format('HH:mm');
var date_end = $.fullCalendar.moment(event.end).format('DD.MM.YYYY HH:mm');
$('#modal-event #delete').attr('data-id', event.id);
$('#updatemodal').attr("action", '/events/'+event.id);
$('#modal-event #title').val(event.title);
$('#modal-event #description').val(event.description);
$('#modal-event #date_start').val(date_start);
$('#modal-event #time_start').val(time_start);
$('#modal-event #date_end').val(date_end);
$('#modal-event #responsabile').val(event.responsabile);
$('#modal-event #tipologia_evento_id').val(event.tipologia_evento_id);
$('#modal-event').modal('show');
}
});
我尝试使用@if(!in_array(old('_tipologia_evento_id'),array(1,2)))
但效果不佳。
一些建议?
答案 0 :(得分:0)
你的领域有拼写错误。您的第一个字段在此引用了tipologia_evento_id
:
<select id="tipologia_evento_id" name="tipologia_evento_id" class="form-control" disabled>
<!-- Take note it has no _ (underscore) starting -->
但是你想用_
来访问该值,从这里开始:
@if(old('_tipologia_evento_id') == $tipologia->id)
在这里:
@if(!in_array(old('_tipologia_evento_id'),array(1,2)))