kafe.form

Class

Version 1.4.2

Utilitary methods for html forms and related interactions.

Source: dist/form.js

Methods

autofocusOnNext

Automaticaly jump the focus to the next field once the maxlength has been reached.

autofocusOnNext
  • selector

Parameters:

  • selector String|jQueryObject|DOMElement

    Selector of text-based form elements.

Example:

kafe.form.autofocusOnNext('.first-name, .last-name, .email');
$('.first-name, .last-name, .email').kafe('form.autofocusOnNext');

maxLength

Adds a simulated maxlength support for textarea elements.

maxLength
  • selector
  • max
  • block = false
  • callback

Parameters:

  • selector String|jQueryObject|DOMElement

    Selector of text-based form elements.

  • max Integer

    Maximum number of characters.

  • [block = false] Boolean Optional

    Prevent further character entry once the limit is reached.

  • [callback] Function Optional

    Callback triggered when the character limit is reached. The current number of characters is provided as the first argument of the callback.

Example:

kafe.form.maxLength('.twitter-post', 140, false, function(count) {
					    console.log(count);
					});
$('.twitter-post').kafe('form.maxLength', 140, false, function(count) {
					    console.log(count);
					});

onEnter

Detects the RETURN key, then triggers a callback.

onEnter
  • selector
  • callback

Parameters:

  • selector String|jQueryObject|DOMElement

    Selector of text-based form elements.

  • callback Function

    Function to be fired by the keypress.

Example:

kafe.form.onEnter('.search-field', function(input) {
					    $(input).parents('form').submit();
					});
$('.search-field').kafe('form.onEnter', function(input) {
					    $(input).parents('form').submit();
					});

passwordStrength

Calculates the password strength value of given fields.

passwordStrength
  • selector
  • callback

Parameters:

  • selector String|jQueryObject|DOMElement

    Selector of text-based form elements.

  • [callback] Function Optional

    Callback triggered when the value is changed. The calculated strengh value is provided as the first argument of the callback.

Example:

kafe.form.passwordStrength('.password', function(strengh) {
					    console.log(strengh);
					});
$('.password').kafe('form.passwordStrength', function(strengh) {
					    console.log(strengh);
					});

placeholder

Adds support for the placeholder attribute for older browsers (Older than IE10). If applied, a "Placeholder" class will also be present when the placeholder text is shown.

placeholder
  • selector

Parameters:

  • [selector] String Optional

    Selector of text-based form elements. Defaults to 'input[placeholder], textarea[placeholder]' when left undefined.

Example:

kafe.form.placeholder('.search-field');
$('.search-field').kafe('form.placeholder');

replaceSubmit

Replace elements with a submit button

replaceSubmit
  • selector = 'input:submit'

Parameters:

  • [selector = 'input:submit'] String|jQueryObject|DOMElement Optional

    Elements to replace

Example:

kafe.form.replaceSubmit();
$('.Search input:submit').kafe('form.replaceSubmit');

sanitizeFormData

Sanitize form text entry for .NET validator.

sanitizeFormData
  • selector

Parameters:

  • selector String|jQueryObject|DOMElement

    Reference to the current .NET form.

Example:

kafe.form.sanitizeFormData('#Form1');
$('#Form1').form('form.sanitizeFormData');

selectPlaceholder

Adds support for a pseudo-placeholder attribute for select elements. If applied, a "Placeholder" class will also be present when the placeholder text is shown.

selectPlaceholder (  )

Example:

kafe.form.selectPlaceholder();