0.1.0 • Published 6 years ago

jquery-form-readonly v0.1.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

License

jquery-form-readonly

This is a jQuery plug-in that makes HTML form elements read-only.

Usage

Install

Include jquery-form-readonly after jQuery library.

<script src="//code.jquery.com/jquery-3.2.1.js"></script> <!-- jQuery -->
<script src="//cdn.jsdelivr.net/gh/mozq/jquery-form-readonly@0.1.0/dist/jquery.form-readonly.min.js"></script> <!-- jquery-form-readonly -->

Enable read-only

Please call .formReadonly() method.

$('form').formReadonly();

You can apply this method for any jQuery elements.

$('input[type="text"]').formReadonly();
$('div.fooClass').formReadonly();
$('#barId').formReadonly();

The following elements contains in jQuery elements is to be processed.

ElementType
inputtext, password, checkbox, radio, file
textareaN/A
selectN/A

Options

You can specify following options.

OptionTypeDescriptionDefault value
multipleSeparatorstring, element, etc...Separator of multiple value', '
passwordMaskCharstringCharacter of password mask'*'
passwordMaskLengthnumberFixed length of password-1 (not fixed)
useLabelbooleanUse label when presented by checkbox or radiofalse
includesReadonlybooleanIncludes read-only form elements to targetfalse
includesDisabledbooleanIncludes disabled form elements to targetfalse
excludesfunction(p1)Function to exclude form elementsnull

Sample code:

$('form').formReadonly({
  multipleSeparator: $('<br>'),
  passwordMaskChar: '#',
  passwordMaskLength: 16,
  useLabel: true,
  includesReadonly: true,
  includesDisabled: true,
  excludes: function ($elm) { return ($elm.prop('type') === 'radio'); },
});

Cancel read-only

Specifying false for the argument cancels read-only.

$('form').formReadonly(false);

License

The jquery-form-readonly is open-sourced software licensed under the MIT license.