承接 faryshta/yii2-disable-submit-buttons 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

faryshta/yii2-disable-submit-buttons

最新稳定版本:2.0.0

Composer 安装命令:

composer require faryshta/yii2-disable-submit-buttons

包简介

Yii2 asset to automatically disable submit buttons on Yii2 ActiveForm.

README 文档

README

Latest Stable Version Total Downloads Latest Unstable Version License

Yii2 asset to automatically disable submit buttons on Yii2 ActiveForm.

Installation

The preferred way to install this extension is through composer.

Either run

composer require "faryshta/yii2-disable-submit-buttons:~2.0.0"

or add

"faryshta/yii2-disable-submit-buttons": "~2.0.0"

to the require section of your composer.json file.

Register Asset

Register the faryshta\disableSubmitButtons\Asset, preferably on your AppAsset dependencies

use faryshta\disableSubmitButtons\Asset as DisableSubmitButtonAsset;

class AppAsset extends yii\web\AssetBundle
{
    public $depends = [
        DisableSubmitButtonsAsset::class,
        // other dependencies
    ];
}

Usage

Add css class disable-submit-buttons to your [ActiveForm] (http://www.yiiframework.com/doc-2.0/yii-widgets-activeform.html) widget.

Optionally if you want to change the text on a button, add the attribute data-disabled-text with the text to be changed.

$form = ActiveForm::begin([
    'options' => ['class' => 'disable-submit-buttons'],
    // other configurations
]);

    // inputs

    Html::submitButton('Submit', [
        // optional, will show the value of `data-disabled-text` attribute
        // while handling the validation and submit
        'data' => ['disabled-text' => 'Please Wait']
    ])

$form->end();

With this the :input[type="submit"] buttons will be disabled and if the validation fails the buttons will be enabled again.

Javascript

This asset adds 2 methods on jQuery disableSubmitButtons() and enableSubmitButtons() which can be called from a <form> tag generated by ActiveForm widget.

Ajax Example

The following example submits the form using ajax and enables the submit buttons so the ur ser can send another form after completing the ajax request.

$form = ActiveForm::begin([
    'id' => 'ajax-form',
    'options' => ['class' => 'disable-submit-buttons'],
]);
    echo $form->field($model, 'name');

    echo Html::submitButton('Submit', [
        'data' => ['disabled-text' => 'Validating'],
    ]);

$form->end();

$this->registerJsFile('ajax-form.js');

Then on ajax-form.js

$('#ajax-form').on('beforeSubmit', function () {
  var $yiiform = $(this);
  $.ajax(
    {
      type: $yiiform.attr('method'),
      url: $yiiform.attr('action'),
      data: $yiiform.serializeArray(),
    }
  ).done(function(data) {
    // success actions
    $yiiform.enableSubmitButtons(); // enable the submit buttons
  });

  return false; // prevent default form submission
});

Live Demo

You can run a live demo of this library with the following composer commands

composer deploy-tests
composer yii serve

License

The BSD License (BSD). Please see License File for more information.

统计信息

  • 总下载量: 435.1k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 17
  • 点击次数: 1
  • 依赖项目数: 1
  • 推荐数: 0

GitHub 信息

  • Stars: 16
  • Watchers: 1
  • Forks: 10
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固