I need to create a CActiveForm that allows decimal values to be entered into a numberField.
The model rules include setting that attribute’s integerOnly value to false, but it seems like the problem is with the form, not the model’s validation rules. When I try to submit the form with a decimal value, it tells me to enter a valid value.
The message depends on the browser that I’m using. Safari says, “Enter a valid value.” Chrome says, “Please enter a valid value. The two nearest valid values are x and y.” where x and y are the two closest integers to what I input.
Has anybody experienced this or does anyone know how to correct it?
Following is code similar to what I have:
Form
<?php $form = $this->beginWidget('CActiveForm', array(
'action' => Yii::app()->createUrl('person/create', array(
'school' => $school->id
)),
'method' => 'get',
'htmlOptions' => array(
'class' => 'generic-form'
)
)); ?>
<div class="row">
<div class="left field-container one-fourth">
<?= $form->label($person, 'name') ?>
<?= $form->textField($person, 'name') ?>
</div>
<div class="left field-container one-fourth">
<?= $form->label($person, 'height') ?>
<?= $form->numberField($person, 'height') ?>
</div>
<div class="left field-container one-fourth">
<?= $form->label($person, 'age') ?>
<?= $form->numberField($person, 'age') ?>
</div>
<div class="left one-fourth">
<?= TbHtml::submitButton('', array(
'id' => 'submit-create-person',
'class' => 'fa fa-plus generic-button'
)); ?>
</div>
</div>
<?php $this->endWidget() ?>
Model
public function rules()
{
return array(
array('school_id', 'required'),
array('name', 'safe'),
array('height', 'numerical', 'integerOnly' => false),
array('age', 'numerical', 'integerOnly'=>true),
);
}