我有这个表单,用户使用j查询功能添加输入行。我正在尝试添加另一个j查询函数,该函数检查以确保新行中的一个输入在下一个之前填写。输入状态取决于输入类型。我试图这样做,当用户在类型输入之前单击子状态输入时,他们会收到一条消息,告诉他们先填充先前的输入。 添加输入行的函数:
var component_row = <?php echo $component_row; ?>;
function addComponents(language_id) {
html = ' <tr id="component-row' + component_row + '">';
html += ' <td class="text-right"><input type="text" name="component_module[' + component_row + '][component_name]" value="" class="form-control" /></td>';
html += ' <td class="text-right component-dropdown"><div class="component-dropdowns"> <select class="component_type_selection" name="component_module[' + component_row + '][component_type]" row_number="'+component_row+'" id="bobo'+component_row+'"><option value=""><?php echo $text_select; ?></option><option value="Email"><?php echo "Email" ?></option><option value="Text Message"><?php echo "Text Message" ?></option><option value="Direct Mail"><?php echo "Direct Mail" ?></option><option value="Transnational Email"><?php echo "Transnational Email" ?></option><option value="EVENT"><?php echo "Event" ?></option> </select><div></td>';
html += ' <td class="text-right component-dropdown"><div class="component-dropdowns"> <select class="component_status_options" name="component_module[' + component_row + '][component_status]" row_number="'+component_row+'" id="list'+component_row+'"></select><p class="warning"></p><div> </td>';
html += ' <td class="text-right component-dropdown"><div class="component-dropdowns"> <select name="component_module[' + component_row + '][component_owner]" ><option value=""><?php echo $text_select; ?></option><?php foreach ($users as $user) { ?><option value="<?php echo $user['username']; ?>" ><?php echo $user['username']; ?></option><?php } ?> </select></div></td>';
html += ' <td class="text-right" id="comp-cal"><div class="input-group date required"><input type="text" name="component_module[' + component_row + '][component_start_date]" placeholder="<?php echo $entry_date; ?>" data-date-format="YYYY-MM-DD" class="form-control" /><span class="input-group-btn" id="component-calendar-btn">';
html += ' <button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button></span></div></td>';
html += ' <td class="text-left"><button type="button" onclick="$(\'#component-row' + component_row + '\').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>';
html += '</tr>';
$('#components tbody').append(html);
$('.date').datetimepicker({
formatDate:'yyyy-mm-dd',
formatDate:'yyyy-mm-dd',
pickTime: false
});
component_row++;
}
我试图用来添加消息的功能
$( '.component_status_options').focus(function() {
$(this).siblings('p').text('Please select Type first')
});
html:
<div class="wrapper">
<div class="panel-heading">
<h3 class="panel-title"><i class="fa fa-pencil"></i> <?php echo $text_add_component; ?></h3>
</div>
<div class="panel-body" id="addon">
<div class=" col-lg-10 col-lg-push-1 form-group" >
<div class="tab-pane" id="tab-special">
<div class="table-responsive" id="component-module">
<table id="components" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<td class="text-left"><?php echo $entry_name; ?></td>
<td class="text-left"><?php echo $text_filter_type; ?></td>
<td class="text-left"><?php echo $entry_status; ?></td>
<td class="text-left"><?php echo $entry_owner; ?></td>
<td class="text-left"><?php echo $entry_component_start_date; ?></td>
<td></td>
</tr>
</thead>
<tbody>
<?php $component_row = 0; ?>
<?php if(isset($component_modules)){ ?>
<?php foreach ($component_modules as $component_module) { ?>
<tr id="component-row<?php echo $component_row; ?>">
<td class="text-left"><input type="text" name="component_module[<?php echo $component_row; ?>][component_name]" value="<?php echo $component_module['component_name']; ?>" class="form-control" /></td>
<td class="text-left"><input class="form-control" name="component_module[<?php echo $component_row; ?>][component_type]"value="<?php echo $component_module['component_type']; ?>"/ readonly></td>
<td class="text-left"><input class="form-control" name="component_module[<?php echo $component_row; ?>][component_status]"value="<?php echo $component_module['component_status']; ?>"/ readonly></td>
<td class="text-left"><div class="component-dropdowns"><select name="component_module[<?php echo $component_row; ?>][component_owner]" class="form-control"><?php foreach ($users as $user) { ?>
<option value="<?php echo $user['username']; ?>" <?php echo ($component_module['component_owner'] == $user['username']) ? 'selected' : ''; ?>><?php echo $user['username']; ?></option><?php } ?> </select></div>
</td>
<td class="text-left"><div class="input-group date required"><input type="text" name="component_module[<?php echo $component_row; ?>][component_start_date]" value="<?php echo $component_module['component_start_date']; ?>" data-date-format="YYYY-MM-DD" class="form-control" /><span class="input-group-btn" id="component-calendar-btn"><button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button></span></div></td>
<input type="hidden" name="component_module[<?php echo $component_row; ?>][component_parent_id]" value="<?php echo $component_module['parent_id']; ?>" class="form-control" />
<td class="text-left"><button type="button" onclick="$('#component-row<?php echo $component_row; ?>').remove();" data-toggle="tooltip" title="<?php echo $button_remove; ?>" class="btn btn-danger"><i class="fa fa-minus-circle"></i></button></td>
</tr>
<?php $component_row++; ?>
<?php } ?>
<?php }else{ ?>
<tr>
<td colspan="5" class="text-center">No components </td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<td colspan="5"></td>
<td class="text-right"><button type="button" onclick="addComponents();" data-toggle="tooltip" title="<?php echo $button_add; ?>" class="btn btn-primary"><i class="fa fa-plus-circle"></i></button></td>
</tr>
</tfoot>
</table>
<?php if ($error_component_name) { ?>
<div class="text-danger"><?php echo $error_component_name; ?></div>
<?php } ?>
<?php if ($error_component_type) { ?>
<div class="text-danger"><?php echo $error_component_type; ?></div>
<?php } ?>
<?php if ($error_component_status) { ?>
<div class="text-danger"><?php echo $error_component_status; ?></div>
<?php } ?>
<?php if ($error_component_owner) { ?>
<div class="text-danger"><?php echo $error_component_owner; ?></div>
<?php } ?>
<?php if ($error_date_beginning) { ?>
<div class="text-danger"><?php echo $error_date_beginning; ?></div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>