提示模态的日期范围不能用作所述模态中的变量



在我的预订页面上,我选择了两个日期范围,然后显示模式弹出窗口。我正在尝试在2个日期范围内工作(即两个日期之间的天数、预订开始日期等(。

在主页中这样做很好,但我的值在模式弹出窗口中不起作用。我认为这是因为我需要使用的值实际上是提示弹出的值。

<!-- Modal -->

<div class="modal fade" id="owner_price_modal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog custom_price_dialog">
<div class="modal-content">
<div class="modal-header"> 
<button type="button" id="close_custom_price_internal" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h2 class="modal-title_big"><?php esc_html_e('Custom Price','wprentals');?></h2>
<h4 class="modal-title" id="myModalLabel"><?php esc_html_e('Set custom price for selected period - test','wprentals');?></h4>
</div>

<div class="modal-body">
<div id="booking_form_request_mess_modal"></div>    
<div class="col-md-6">
<label for="start_date_owner_book"><?php esc_html_e('Start Date','wprentals');?></label>
<input type="text" id="start_date_owner_book" size="40" name="booking_from_date" class="form-control" value="">


</div>
<div class="col-md-6">
<label for="end_date_owner_book"><?php  esc_html_e('End Date','wprentals');?></label>
<input type="text" id="end_date_owner_book" size="40" name="booking_to_date" class="form-control" value="">
</div>

<input type="hidden" id="property_id" name="property_id" value="" />
<input name="prop_id" type="hidden"  id="agent_property_id" value="">
<div class="col-md-6">
<label for="coment"><?php echo esc_html__( 'New Price in ','wprentals').' '.esc_html($wp_estate_currency_symbol);?></label>
<input type="text" id="new_custom_price" size="40" name="new_custom_price" class="form-control" value="">
</div>    

<div class="col-md-6">
<label for="period_extra_price_per_guest"><?php echo wpestate_show_labels('extra_price_per_guest',$rental_type,$booking_type).' '.esc_html($wp_estate_currency_symbol);?></label>
<input type="text" id="period_extra_price_per_guest" size="40" name="period_extra_price_per_guest" class="form-control" value="0">
</div> 
<div class="col-md-6">
<label for="period_week_price"><?php  echo wpestate_show_labels('price_week_label',$rental_type,$booking_type);?></label>
<input type="text" id="period_week_price" size="40" name="period_week_price" class="form-control" value="">
</div> 
<div class="col-md-6">
<label for="period_month_price"><?php echo wpestate_show_labels('price_month_label',$rental_type,$booking_type);?></label>
<input type="text" id="period_month_price" size="40" name="period_month_price" class="form-control" value="">
</div>       
<div class="col-md-6">
<label for="period_price_per_weekeend"><?php echo esc_html__( 'Price per weekend in ','wprentals').' '.esc_html($wp_estate_currency_symbol);?></label>
<input type="hidden" id="period_price_per_weekeend" size="40" name="period_price_per_weekeend" class="form-control" value="">

</div>
<div class="col-md-6">
<label for="period_min_days_booking"><?php echo esc_html__( 'Minimum days of booking','wprentals');?></label>
<input type="text" id="period_min_days_booking" size="40" name="period_min_days_booking" class="form-control" value="">
</div>


<div class="col-md-6">
<label for="period_checkin_change_over"><?php echo esc_html__( 'Allow only bookings starting with the check in on changeover days','wprentals');?></label>
<select id="period_checkin_change_over" name="period_checkin_change_over" class="select-submit2">
<?php 
foreach($week_days as $key=>$value){
print '   <option value="'.esc_attr($key).'">'.esc_html($value).'</option>';
}
?>
</select>
</div>
<?php
$ajax_nonce = wp_create_nonce( "wprentals_custom_price_nonce" );
print'<input type="hidden" id="wprentals_custom_price" value="'.esc_html($ajax_nonce).'" />    ';
?>
<button type="submit" id="set_price_dates" class="wpb_button  wpb_btn-info  wpb_regularsize   wpestate_vc_button  vc_button"><?php esc_html_e('Set price for period','wprentals');?></button>

</div><!-- /.modal-body -->
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->

我得到的反馈是,它就像下面这样简单,然而,尽管它在主页中有效(仅用于测试目的(,但它在模态中不起作用。在模态中,我得到了无效的日期,我认为这是因为当第一次加载模态时,start_date_owner_book和end_date_oowner_book返回为空值。

var startDate = new Date($("#start_date_owner_book").val());
var endDate = new Date($("#end_date_owner_book").val());
var timeDifference = endDate - startDate;
var differenceInDays = timeDifference / (1000*3600*24);
$("#period_min_days_booking").val(Math.floor(differenceInDays));

感谢您的帮助。热烈问候

首先在两个日期选择中禁用select2,然后查看返回的结果为空。如果检测到select2导致问题,请删除模式组标记中的tabindex="-1"属性。

谢谢肉桂。

这是因为我试图在前2行创建一个日期,该输入是英国格式的,所以每当日期值(在我的字段中为dd-mm-yyyy(超过13或以上时,它就会出错。我必须先把它分解,然后重建,然后确定日期。

最新更新