mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-02 13:02:24 +08:00
Fixes #4225: Added ActiveForm::validateOnBlur and ActiveField::validateOnBlur
This commit is contained in:
@ -175,6 +175,7 @@ Yii Framework 2 Change Log
|
||||
- Fixed PBKDF2 key truncation.
|
||||
- Adjusted API.
|
||||
- Enh #4209: Added `beforeCopy`, `afterCopy`, `forceCopy` properties to AssetManager (cebe)
|
||||
- Enh #4225: Added `ActiveForm::validateOnBlur` and `ActiveField::validateOnBlur` (qiangxue)
|
||||
- Enh #4297: Added check for DOM extension to requirements (samdark)
|
||||
- Enh #4317: Added `absoluteAuthTimeout` to yii\web\User (ivokund, nkovacs)
|
||||
- Enh #4360: Added client validation support for file validator (Skysplit)
|
||||
|
||||
@ -79,6 +79,8 @@
|
||||
encodeError: true,
|
||||
// whether to perform validation when a change is detected on the input
|
||||
validateOnChange: false,
|
||||
// whether to perform validation when the input loses focus
|
||||
validateOnBlur: false,
|
||||
// whether to perform validation when the user is typing.
|
||||
validateOnType: false,
|
||||
// number of milliseconds that the validation should be delayed when a user is typing in the input field.
|
||||
@ -235,7 +237,10 @@
|
||||
if (attribute.validateOnChange) {
|
||||
$input.on('change.yiiActiveForm',function () {
|
||||
validateAttribute($form, attribute, false);
|
||||
}).on('blur.yiiActiveForm', function () {
|
||||
});
|
||||
}
|
||||
if (attribute.validateOnBlur) {
|
||||
$input.on('blur.yiiActiveForm', function () {
|
||||
if (attribute.status == 0 || attribute.status == 1) {
|
||||
validateAttribute($form, attribute, !attribute.status);
|
||||
}
|
||||
|
||||
@ -95,10 +95,15 @@ class ActiveField extends Component
|
||||
*/
|
||||
public $enableAjaxValidation;
|
||||
/**
|
||||
* @var boolean whether to perform validation when the input field loses focus and its value is found changed.
|
||||
* @var boolean whether to perform validation when the value of the input field is changed.
|
||||
* If not set, it will take the value of [[ActiveForm::validateOnChange]].
|
||||
*/
|
||||
public $validateOnChange;
|
||||
/**
|
||||
* @var boolean whether to perform validation when the input field loses focus.
|
||||
* If not set, it will take the value of [[ActiveForm::validateOnBlur]].
|
||||
*/
|
||||
public $validateOnBlur;
|
||||
/**
|
||||
* @var boolean whether to perform validation while the user is typing in the input field.
|
||||
* If not set, it will take the value of [[ActiveForm::validateOnType]].
|
||||
@ -717,7 +722,7 @@ class ActiveField extends Component
|
||||
$inputID = Html::getInputId($this->model, $this->attribute);
|
||||
$options['id'] = $inputID;
|
||||
$options['name'] = $this->attribute;
|
||||
foreach (['validateOnChange', 'validateOnType', 'validationDelay'] as $name) {
|
||||
foreach (['validateOnChange', 'validateOnBlur', 'validateOnType', 'validationDelay'] as $name) {
|
||||
$options[$name] = $this->$name === null ? $this->form->$name : $this->$name;
|
||||
}
|
||||
$options['container'] = isset($this->selectors['container']) ? $this->selectors['container'] : ".field-$inputID";
|
||||
|
||||
@ -100,10 +100,15 @@ class ActiveForm extends Widget
|
||||
*/
|
||||
public $validateOnSubmit = true;
|
||||
/**
|
||||
* @var boolean whether to perform validation when an input field loses focus and its value is found changed.
|
||||
* @var boolean whether to perform validation when the value of an input field is changed.
|
||||
* If [[ActiveField::validateOnChange]] is set, its value will take precedence for that input field.
|
||||
*/
|
||||
public $validateOnChange = true;
|
||||
/**
|
||||
* @var boolean whether to perform validation when an input field loses focus.
|
||||
* If [[ActiveField::$validateOnBlur]] is set, its value will take precedence for that input field.
|
||||
*/
|
||||
public $validateOnBlur = true;
|
||||
/**
|
||||
* @var boolean whether to perform validation while the user is typing in an input field.
|
||||
* If [[ActiveField::validateOnType]] is set, its value will take precedence for that input field.
|
||||
|
||||
Reference in New Issue
Block a user