This is a Drupal module that integrates the cleave.js input field auto-formatter with the Drupal form-API.

This is pure API module without any UI. You only need to install it, when anoher module depends on it.

Dependencies

Installation

Install this module and its dependencies like any other Drupal modules.

For installing the library:

  1. Go to https://github.com/nosir/cleave.js and download one of the releases.
  2. Put it in a libraries-folder as described in the libraries documentation. Make sure the folder is named cleave.js.

Usage

When you add #cleave-property to any of your form-API elements Cleave will be invoked automatically on the resulting HTML element using this config.

Example:

<span class="token variable">$form</span><span class="token punctuation">[</span><span class="token string">'numeral'</span><span class="token punctuation">]</span> <span class="token operator">=</span> <span class="token punctuation">[</span>
  <span class="token string">'#type'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'textfield'</span><span class="token punctuation">,</span>
  <span class="token string">'#title'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token function">t</span><span class="token punctuation">(</span><span class="token string">'Numeral'</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token string">'#cleave'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token punctuation">[</span>
    <span class="token string">'numeral'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token constant">TRUE</span><span class="token punctuation">,</span>
    <span class="token string">'numeralThousandsGroupStyle'</span> <span class="token operator">=</span><span class="token operator">></span> <span class="token string">'thousand'</span><span class="token punctuation">,</span>
  <span class="token punctuation">]</span><span class="token punctuation">,</span>
<span class="token punctuation">]</span><span class="token punctuation">;</span>

Devlopment

Development on this module is happening mainly on github. Feel free to post issues and pull requests there.

Note: Development branches on drupal.org might be outdated because they are only pushed to in order to tag releases.

Supporting organizations: 
Development of this module

Project information

Releases