Form reset mixin

Form Reset Mixin

Form Reset Mixin

Description: A mixin to call refresh() on an input widget when the parent form gets reset.

QuickNavExamples

Options

Events

This only works for native input elements that have a form attribute, like an <input>. It doesn't work for other elements like <label> or <div>

Methods

_bindFormResetHandler()Returns: jQuery (plugin only)

Call this._bindFormResetHandler() inside _create() to initialize the mixin.
  • This method does not accept any arguments.
Code examples:

Set the background color of the widget's element based on an option.

_create: function() {
  this._bindFormResetHandler();
}

_unbindFormResetHandler()Returns: jQuery (plugin only)

Call this._unbindFormResetHandler() inside _destroy() to destroy the mixin.
  • This method does not accept any arguments.
Code examples:
_destroy: function() {
  this._unbindFormResetHandler();
}

Example:

Type colors into the input

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>jQuery.ui.formResetMixin demo</title>
  <link rel="stylesheet" href="/doc_/-code-jquery-com-ui-1-12-0-themes-smoothness-jquery-ui-css.html?lang=en">
  <style>
  .demo-colorize-swatch {
    width: 50px;
    height: 50px;
    border: 1px solid black;
  }
  </style>
  <script src="//code.jquery.com/jquery-1.12.4.js" rel="external nofollow" ></script>
  <script src="//code.jquery.com/ui/1.12.0/jquery-ui.js" rel="external nofollow" ></script>
</head>
<body>
 
<form>
  <input id="colorize">
  <button type="reset">Reset form</button>
</form>
 
<script>
$.widget( "custom.colorize", [ $.ui.formResetMixin, {
  _create: function() {
    this.swatch = $("<div>")
      .addClass("demo-colorize-swatch")
      .insertAfter(this.element);
 
    this.refresh();
    this._bindFormResetHandler();
 
    this._on({ keyup: "refresh" });
  },
  refresh: function() {
    this.swatch.css( "background-color", this.element.val() );
  },
  _destroy: function() {
    this.swatch.remove();
    this._unbindFormResetHandler();
  }
} ] );
$( "#colorize" ).colorize();
</script>
 
</body>
</html>

Demo:

© The jQuery Foundation and other contributors
Licensed under the MIT License.
https://api.jqueryui.com/form-reset-mixin

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部