在yii中,我在yii 1.1.x的clientoptions中找到validateonchange和validateontype
但我需要ajax是启用的,如果客户端在textfield中输入空格,就像stackoverflow中的标记一样
这是我的表单.php

    <?php
/* @var $this TextController */
/* @var $model Text */
/* @var $form CActiveForm */
?>

<div class="form">

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'text-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'=>TRUE,
     'focus'=>array($model,'subject'),
     'clientOptions'=>array(
                'validateOnChange'=>true,  // the default. validate when input changes
                'validateOnType'=>'true',    // validate with EVERY keystroke, hooray!
                'validationDelay'=>10,     // not related to this post--but cool!
                                      // default delay is 200 ms
        ),
)); ?>

    <p class="note">Fields with <span class="required">*</span> are required.</p>

    <?php echo $form->errorSummary($model); ?>

    <div class="row">
        <?php echo $form->labelEx($model,'subject'); ?>
        <?php echo $form->textField($model,'subject',array('size'=>60,'maxlength'=>80)); ?>
        <?php echo $form->error($model,'subject'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'matn'); ?>
        <?php echo $form->textField($model,'matn',array('size'=>60,'maxlength'=>255)); ?>
        <?php echo $form->error($model,'matn'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'group'); ?>
        <?php echo $form->textField($model,'group',array('size'=>20,'maxlength'=>20)); ?>
        <?php echo $form->error($model,'group'); ?>
    </div>
<?php $userX=yii::app()->session['idX']; ?>

    <div class="row">
        <?php // echo $form->labelEx($model,'user_id'); ?>
        <?php echo $form->textField($model,'user_id',array ('value'=>$userX,'type'=>"hidden")); ?>
        <?php // echo $form->error($model,'user_id'); ?>
    </div>

    <div class="row">
        <?php echo $form->labelEx($model,'Privacy'); ?>
        <?php echo $form->dropDownList($model,'Privacy',  array('1'=>'Public','2'=>'Only me')); ?>
        <?php echo $form->error($model,'Privacy'); ?>
    </div>

    <div class="row buttons">
        <?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save'); ?>
    </div>

<?php $this->endWidget(); ?>

</div><!-- form -->

最佳答案

这个jquery代码有帮助吗?:

$("input[type='text']").keyup(function(e){
    if(e.keyCode == 32)
    {
        //AJAX action(s)
    }
})

关于php - yii:如果客户端在textfield中插入空格,如何启用ajax,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24118973/

10-15 04:59