remove function in JavaScript validation
-
15-10-2022 - |
Вопрос
I am new to Yii. I have did a JavaScript validation part in my view. I am adding a new host, service Id to a customer, if I click on ADD MORE, it again give me the two fields to add another one, but remove function is not working here. and suppose if I enter blank value in the fields after adding more, then it must return some error message, how to do this, please help me. Thanks in advance.
My view:
<div id="content">
<div class="innerLR">
<div class="row-fluid">
<div class="form">
<?php
echo $id = $id;
$form = $this->beginWidget ( 'CActiveForm', array (
'id' => 'nimsoft-host-form',
// Please note: When you enable ajax validation, make sure the corresponding
// controller action is handling ajax validation correctly.
// There is a call to performAjaxValidation() commented in generated controller code.
// See class documentation of CActiveForm for details on this.
'enableAjaxValidation' => false
) );
?>
<fieldset>
<legend>Customer Host Information:</legend>
<?php echo $form->errorSummary($model); ?>
<div id="add_details">
<tr>
<td style="text-align: left;" class="tdSpan">
<?php echo $form->labelEx($model, 'host_name'); ?>
</td>
<td class="tdSpan">
<div class="row">
<?php echo $form->textField($model, 'host_name', array('size' => 60, 'maxlength' => 88)); ?>
</div>
</td>
</tr>
<tr>
<td style="text-align: left;" class="tdSpan">
<?php echo $form->labelEx($model, 'host_serviceid'); ?>
</td>
<td class="tdSpan">
<div class="row">
<?php echo $form->textField($model, 'host_serviceid', array('rows' => 6, 'cols' => 50)); ?>
</div>
</td>
</tr>
</div>
<tr class="tdSpan">
<td></td>
<td>
<div>
<div class="row">
<?php //echo $form->labelEx($model,'prod_avl_date'); ?>
<?php
$this->widget ( 'zii.widgets.jui.CJuiDatePicker', array (
'name' => 'Products[prod_avl_date]',
// additional javascript options for the date picker plugin
'options' => array (
'showAnim' => 'fold',
'dateFormat' => 'yy/mm/dd'
)
,
'htmlOptions' => array (
'style' => 'height:20px;'
)
) );
?>
<?php //echo $form->error($model,'prod_avl_date'); ?>
</div>
<div class="row">
<?php //echo $form->labelEx($model,'prod_end_date'); ?>
<?php
$this->widget ( 'zii.widgets.jui.CJuiDatePicker', array (
'name' => 'Products[prod_end_date]',
// additional javascript options for the date picker plugin
'options' => array (
'showAnim' => 'fold',
'dateFormat' => 'yy/mm/dd'
)
,
'htmlOptions' => array (
'style' => 'height:20px;'
)
) );
?>
<?php //echo $form->error($model,'prod_end_date'); ?>
</div>
</div>
<div class="row buttons">
<h2>
<a href="#" id="addHost">Add Another Host</a>
</h2>
<div> </div>
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save', array('onclick' => 'return checkForm();')); ?>
</div>
</td>
</tr>
</tbody>
</table>
<?php $this->endWidget(); ?>
</fieldset>
</div>
</div>
</div>
</div>
<div id="footer" class="hidden-print">
<?php $this->renderPartial('application.views.layouts._footer_inc'); ?>
</div>
<script>
$('#addHost').click(function()
{
$('#add_details').append('<?php echo $form->labelEx($model, 'host_name'); ?>
<?php echo $form->textField($model, 'host_name', array('size' => 60, 'maxlength' => 88)); ?>
<?php echo $form->labelEx($model, 'host_serviceid'); ?>
<?php echo $form->textField($model, 'host_serviceid', array('rows' => 6, 'cols' => 50)); ?><a href="#" id="remove">REMOVE</a>');
$("remove").on("click",".removeclass", function(e){ //user click on remove text
if( x > 1 ) {
$(this).parent('add_details').remove(); //remove text box
x--; //decrement textbox
}
return false;
})
});
</script>
Нет правильного решения
Не связан с StackOverflow