我陷入逻辑状态,我有一个表单,当单击一个名为全天事件的复选框时,两个输入文本被禁用,称为输入开始时间和结束时间。需要剩余的输入文本来填补价值。当我点击复选框全天活动时,问题就出现了。并在剩余的三个文本字段中填充值,然后单击“保存”按钮。然后我在禁用的文本字段底部收到验证错误消息。当选中复选框并且禁用字段为空时,会阻止保存表单和显示底部的错误消息。这是我面临的问题
选中复选框后,禁用字段中包含一些值,然后正确保存
这是jsp
<form action="" method="">
<div class="left-add">
<div class="fbox">
<input name="oldEventName" id="oldEventName" type="hidden" value="aaa">
<label for="eventName"><span></span>Event Name</label>
<input type="text" id="eventName" maxlength="40" value="">
</div>
<br clear="all">
<h3 style="margin:30px 0;display:block;clear:both;">Event time</h3>
<div class="fbox timepicker">
<label for="startDate"><span></span>Start Date</label>
<input type="text" id="startDate" value="" class="hasDatepicker">
</div>
<div class="fbox timepicker">
<label for="startTime"><span></span>Start Time</label>
<input type="text" id="startTime" value="" placeholder="Ex: 08:00" disabled="">
</div>
<div class="fbox timepicker" style="width:250px !important;">
<select name="startTime_ampm" id="startTime_ampm" class="select" style="margin-top: 41px;width:100px;" disabled="">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
<input id="allDayEvent" name="allDayEvent" type="checkbox" value="true">
<label for="allDayEvent" style="float: right; margin: 35px 0 0 0;"><span></span>All Day Event</label>
</div>
<br clear="all">
<div class="fbox timepicker">
<label for="endDate"><span></span>End Date</label>
<input type="text" id="endDate" value="" class="hasDatepicker">
</div>
<div class="fbox timepicker">
<label for="endTime"><span></span>End Time</label>
<input type="text" id="endTime" value="" placeholder="Ex: 08:00" disabled="">
</div>
<div class="fbox timepicker" style="width:250px !important;">
<select name="endTime_ampm" id="endTime_ampm" class="select" style="margin-top: 41px;width:100px;" disabled="">
<option value="AM">AM</option>
<option value="PM">PM</option>
</select>
</div>
<div class="bttns">
<input type="button" id="bttn_save" class="bttn save" value="Save" onclick="saveEventForEditOrCreate()">
</div>
</form></div>
</div>
整个表单的和jquery函数如下
function saveEventForEditOrCreate() {
$('.custom_error_msg').remove();
var eventName=$('#eventName').val().trim();
if(eventNames.indexOf(eventName)>-1){
validationError("eventName", "This is an invalid event name. Please update the name and try again.");
return true;
}
var startDate = $('#startDate').val();
var endDate = $('#endDate').val();
var startTime=$('#startTime').val();
var endTime=$('#endTime').val();
// if allDayEvent is checked and all fields are empty
if($( "#allDayEvent" ).is( ":checked" ) && $('#eventName').val()==="" && isDate(startDate) === false && isDate(endDate) === false)
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("endDate", "Make have end date");
return true;
}
// if alldayevent is checked and event name start date is empty
else if($( "#allDayEvent" ).is(':checked') && $('#eventName').val()==="" && isDate(startDate) === false)
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
return true;
}
// if alldayevent is checked and event name start date is empty
else if($( "#allDayEvent" ).is(':checked') && $('#eventName').val()==="" && isDate(endDate) === false)
{
validationError("eventName", "Must have event name");
validationError("endDate", "Must have end date");
return true;
}
// if alldayevent is checked and event name is empty
else if($( "#allDayEvent" ).is(':checked') && $('#eventName').val()==="")
{
validationError("eventName", "Must have event name");
return true;
}
// if alldayevent is checked and event name is present and start date is empty
else if($( "#allDayEvent" ).is(':checked') && isDate(startDate) === false)
{
validationError("startDate", "Must have end date");
return true;
}
else if($( "#allDayEvent" ).is(':checked') && $("#startTime").prop('disabled') && $("#endTime").prop('disabled') && validateHHMM($("#startTime").val()) === false && validateHHMM($("#endTime").val()) === false)
{
$("#startTime").empty();
$("#endTime").empty();
return false;
}
else
{
// if alldayevent is checked and event name is present and end date is empty
if($( "#allDayEvent" ).is(':checked') && isDate(endDate) === false )
{
validationError("endDate", "Must have end date");
return true;
}
} //else ends
// if event name and all felds are blank
if($('#eventName').val()==="" && isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
//if event name and all are empty , only start date is filed
else if($('#eventName').val()==="" && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date" );
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // if event name and all are empty , only start time is filed
else if($('#eventName').val()==="" && isDate(startDate) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// if event name and all are empty , only end date is filed
else if($('#eventName').val()==="" && isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // if event name and all are empty , only end time is filed
else if($('#eventName').val()==="" && isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false)
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
return true;
}
// // if event name , start date , start time are empty
else if($('#eventName').val()==="" && isDate(startDate) === false && validateHHMM($("#startTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // if event name , end date , end time are empty
else if($('#eventName').val()==="" && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("endDate", "Must have start date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // if event name , start date , end date are empty
else if($('#eventName').val()==="" && isDate(startDate) === false && isDate(endDate) === false)
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("endDate", "Make have end date");
return true;
}
// if event name , start time , end time are empty
else if($('#eventName').val()==="" && validateHHMM($("#startTime").val()) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// if event name , start date , end time are blank
else if($('#eventName').val()==="" && isDate(startDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // // if event name , start time , end date are blank
if($('#eventName').val()==="" && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false )
{
validationError("eventName", "Must have event name");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
return true;
}
// // // if event name is present and all fields are empty
else if(isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // // if event name , start date are present and all fields are blank
else if(validateHHMM($("#startTime").val()) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // //if event name and end date are present and all fields are blank
else if(isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // // if event name , start time are present and all fields are blank
else if(isDate(startDate) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startDate", "Must have start date");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // // if event name , end time are present and all fields are blank
else if(isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false)
{
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
return true;
}
// // // if event name , start date blank
else if($('#eventName').val()==="" && isDate(startDate) === false)
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
return true;
}
// // // if event name , start time are blank
else if($('#eventName').val()==="" && validateHHMM($("#startTime").val()) === false)
{
validationError("eventName", "Must have event name");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // // if event name , end date are blank
else if($('#eventName').val()==="" && isDate(endDate) === false)
{
validationError("eventName", "Must have event name");
validationError("endDate", "Make have end date");
return true;
}
// if event name , end time are blank
else if($('#eventName').val()==="" && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // if event name is present and start date , end date are blank
else if(isDate(startDate) === false && isDate(endDate) === false )
{
validationError("startDate", "Must have start date");
validationError("endDate", "Make have end date");
return true;
}
// // if event name is present and start time , end time are blank
else if( validateHHMM($("#startTime").val()) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// event name is present and start date , end time are blank
else if(isDate(startDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startDate", "Must have start time");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// event name is present and start time , end date are blank
else if(validateHHMM($("#startTime").val()) === false && isDate(endDate) === false )
{
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
return true;
}
else //event name is filled and all are empty
{
if(isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startDate", "Must have start time");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
} //else ends
//any single fields are empty
if(isDate(startDate) === false) {
validationError("startDate", "Must have start date");
return true;
}
if(isDate(endDate) === false) {
validationError("endDate", "Make have end date");
return true;
}
if(validateHHMM($("#startTime").val()) === false ) {
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
if(validateHHMM($("#endTime").val()) === false ) {
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
if( $("#oldEventName").val() != "" ) {
updateEvent();
}
else {
createEvent();
}
}
答案 0 :(得分:1)
我已经更改了复选框检查条件的条件并且它有效。
function saveEventForEditOrCreate() {
$('.custom_error_msg').remove();
var eventName=$('#eventName').val().trim();
if(eventNames.indexOf(eventName)>-1){
validationError("eventName", "This is an invalid event name. Please update the name and try again.");
return true;
}
var startDate = $('#startDate').val();
var endDate = $('#endDate').val();
var startTime=$('#startTime').val();
var endTime=$('#endTime').val();
if($( "#allDayEvent" ).is( ":checked" )) {
if($('#eventName').val()==="" && isDate(startDate) === false && isDate(endDate) === false)
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("endDate", "Make have end date");
return true;
}
// if alldayevent is checked and event name start date is empty
else if($('#eventName').val()==="" && isDate(startDate) === false)
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
return true;
}
// if alldayevent is checked and event name start date is empty
else if($('#eventName').val()==="" && isDate(endDate) === false)
{
validationError("eventName", "Must have event name");
validationError("endDate", "Must have end date");
return true;
}
// if alldayevent is checked and event name is empty
else if($('#eventName').val()==="")
{
validationError("eventName", "Must have event name");
return true;
}
// if alldayevent is checked and event name is present and start date is empty
else if(isDate(startDate) === false)
{
validationError("startDate", "Must have end date");
return true;
}
else if(isDate(endDate) === false )
{
validationError("endDate", "Must have end date");
return true;
}
} // main if
else {
// if event name and all felds are blank
if($('#eventName').val()==="" && isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
//if event name and all are empty , only start date is filed
else if($('#eventName').val()==="" && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date" );
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // if event name and all are empty , only start time is filed
else if($('#eventName').val()==="" && isDate(startDate) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// if event name and all are empty , only end date is filed
else if($('#eventName').val()==="" && isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // if event name and all are empty , only end time is filed
else if($('#eventName').val()==="" && isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false)
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
return true;
}
// // if event name , start date , start time are empty
else if($('#eventName').val()==="" && isDate(startDate) === false && validateHHMM($("#startTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // if event name , end date , end time are empty
else if($('#eventName').val()==="" && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("endDate", "Must have start date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // if event name , start date , end date are empty
else if($('#eventName').val()==="" && isDate(startDate) === false && isDate(endDate) === false)
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("endDate", "Make have end date");
return true;
}
// if event name , start time , end time are empty
else if($('#eventName').val()==="" && validateHHMM($("#startTime").val()) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// if event name , start date , end time are blank
else if($('#eventName').val()==="" && isDate(startDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // // if event name , start time , end date are blank
if($('#eventName').val()==="" && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false )
{
validationError("eventName", "Must have event name");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
return true;
}
// // // if event name is present and all fields are empty
else if(isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // // if event name , start date are present and all fields are blank
else if(validateHHMM($("#startTime").val()) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // //if event name and end date are present and all fields are blank
else if(isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // // if event name , start time are present and all fields are blank
else if(isDate(startDate) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startDate", "Must have start date");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // // if event name , end time are present and all fields are blank
else if(isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false)
{
validationError("startDate", "Must have start date");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
return true;
}
// // // if event name , start date blank
else if($('#eventName').val()==="" && isDate(startDate) === false)
{
validationError("eventName", "Must have event name");
validationError("startDate", "Must have start date");
return true;
}
// // // if event name , start time are blank
else if($('#eventName').val()==="" && validateHHMM($("#startTime").val()) === false)
{
validationError("eventName", "Must have event name");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // // if event name , end date are blank
else if($('#eventName').val()==="" && isDate(endDate) === false)
{
validationError("eventName", "Must have event name");
validationError("endDate", "Make have end date");
return true;
}
// if event name , end time are blank
else if($('#eventName').val()==="" && validateHHMM($("#endTime").val()) === false )
{
validationError("eventName", "Must have event name");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// // if event name is present and start date , end date are blank
else if(isDate(startDate) === false && isDate(endDate) === false )
{
validationError("startDate", "Must have start date");
validationError("endDate", "Make have end date");
return true;
}
// // if event name is present and start time , end time are blank
else if( validateHHMM($("#startTime").val()) === false && validateHHMM($("#endTime").val()) === false)
{
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// event name is present and start date , end time are blank
else if(isDate(startDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startDate", "Must have start time");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
// event name is present and start time , end date are blank
else if(validateHHMM($("#startTime").val()) === false && isDate(endDate) === false )
{
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
return true;
}
else //event name is filled and all are empty
{
if(isDate(startDate) === false && validateHHMM($("#startTime").val()) === false && isDate(endDate) === false && validateHHMM($("#endTime").val()) === false )
{
validationError("startDate", "Must have start time");
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
validationError("endDate", "Make have end date");
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
} //else ends
//any single fields are empty
if(isDate(startDate) === false) {
validationError("startDate", "Must have start date");
return true;
}
if(isDate(endDate) === false) {
validationError("endDate", "Make have end date");
return true;
}
if(validateHHMM($("#startTime").val()) === false ) {
validationError("startTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
if(validateHHMM($("#endTime").val()) === false ) {
validationError("endTime", "Make sure time is in the HH:MM format. Example: 08:00");
return true;
}
}
// if allDayEvent is checked and all fields are empty
if( $("#oldEventName").val() != "" ) {
updateEvent();
}
else {
createEvent();
}
}