2017 © Pedro Peláez
 

yii2-extension yii2-disable-submit-buttons

Yii2 asset to automatically disable submit buttons on Yii2 ActiveForm.

image

faryshta/yii2-disable-submit-buttons

Yii2 asset to automatically disable submit buttons on Yii2 ActiveForm.

  • Friday, July 28, 2017
  • by Faryshta
  • Repository
  • 1 Watchers
  • 7 Stars
  • 11,542 Installations
  • JavaScript
  • 1 Dependents
  • 0 Suggesters
  • 8 Forks
  • 3 Open issues
  • 2 Versions
  • 55 % Grown

The README.md

Faryshta Yii2 Disable Buttons

Latest Stable Version Total Downloads Latest Unstable Version License, (*1)

Yii2 asset to automatically disable submit buttons on Yii2 ActiveForm., (*2)

Installation

The preferred way to install this extension is through composer., (*3)

Either run, (*4)

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

or add, (*5)

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

to the require section of your composer.json file., (*6)

Register Asset

Register the faryshta\disableSubmitButtons\Asset, preferably on your AppAsset dependencies, (*7)


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., (*8)

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

$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., (*10)

Javascript

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

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., (*12)


$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, (*13)

$('#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, (*14)


composer deploy-tests composer yii serve

License

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

The Versions

28/07 2017

dev-master

9999999-dev https://github.com/Faryshta/yii2-jquery-tagsinput

Yii2 asset to automatically disable submit buttons on Yii2 ActiveForm.

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 jquery yii disable activeform

10/05 2017

1.0.0

1.0.0.0 https://github.com/Faryshta/yii2-jquery-tagsinput

Yii2 asset to automatically disable submit buttons on Yii2 ActiveForm.

  Sources   Download

BSD-3-Clause

The Requires

 

yii2 jquery yii disable activeform