Class: Microform {#class-microform-v2_Id18AFA4004NW}
====================================================

An instance of this class is returned when you create a Microform integration using `flex.microform`. This object allows the creation of Microform Fields. For details, see [Module: Flex](/docs/cybs/en-us/digital-accept-flex/developer/all/rest/digital-accept-flex/microform-integ-v2/micro-v2-reference/api-reference-v2/module-flex-v2.md "").

Methods {#class-microform-v2_id1949H00N0HT}
-------------------------------------------

`createField(fieldType, optionsopt) &gt; {Field}`{#class-microform-v2_clear}  
Create a field for this Microform integration.  
**Parameters**

| Name      | Type   | Attributes         | Description                                                        |
|:----------|:-------|:-------------------|:-------------------------------------------------------------------|
| fieldType | string |                    | Supported values: * `number` * `securityCode`                      |
| options   | object | \&lt;optional\&gt; | To change these options after initialization use `field.update()`. |

**Properties**

| Name          | Type           | Attributes         | Default | Description                                                                                                                                                                                                                            |
|:--------------|:---------------|:-------------------|:--------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| aria-label    | string         | \&lt;optional\&gt; | `true`  | Set the input's label for use by assistive technologies using the [aria-label attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-label "").                                          |
| aria-required | boolean        | \&lt;optional\&gt; | `true`  | Used to indicate through assistive technologies that this input is required for submission using the [aria-required attribute](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Reference/Attributes/aria-required ""). |
| autoformat    | Boolean        | \&lt;optional\&gt; | `true`  | Enable or disable automatic formatting of the input field. This is only supported for number fields and will automatically insert spaces based on the detected card type.                                                              |
| description   | string         | \&lt;optional\&gt; |         | Sets the input's description for use by assistive technologies using the [aria-describedby](https://developer.mozilla.org/en-US/docs/Web/Accessibility/ARIA/Attributes/aria-describedby "") attribute.                                 |
| disabled      | Boolean        | \&lt;optional\&gt; | false   | Sets the `disabled` attribute on the input.                                                                                                                                                                                            |
| maxLength     | number         | \&lt;optional\&gt; | 3       | Sets the maximum length attribute on the input. This is only supported for `securityCode` fields and may take a value of `3` or `4`.                                                                                                   |
| placeholder   | string         | \&lt;optional\&gt; |         | Sets the `placeholder` attribute on the input.                                                                                                                                                                                         |
| styles        | stylingOptions | \&lt;optional\&gt; |         | Apply custom styling to this field.                                                                                                                                                                                                    |
| title         | string         | \&lt;optional\&gt; |         | Sets the [title](https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes/title "") attribute on the input. Typically used to display tooltip text on hover.                                                                |

**Returns**  
Type: Field  
***Examples***  
*Minimal Setup*

```
const= new Flex('.........');
const microform = flex.microform('card');
const number = microform.createField('number');
```

*Providing Custom Styles*

```
const flex = new Flex('.........');
const microform = flex.microform();
const number = microform.createField('number', {
	styles: {
		input: {
			'font-family': '"Courier New", monospace'
		}
	}
});
```

*Providing Custom Styles to All Fields within the `Microform Integration`*

```
const= new Flex('.........');

// apply styles to all fields
const microform = flex.microform('card', { styles: customStyles });

// override the text color for the card number field only
const number = microform.createField('number', { styles: { input: { color: '#000' }}});
```

*Providing Custom Styles to A Specific Field within the `Microform Integration`*

```
const= new Flex('.........');
const microform = flex.microform('card');

const number = microform.createField('number'), {
    styles: {
        input: {
            'font-family': '"Courier New", monospace'
               }
         }});
```

*Setting the Length of a Security Code Field*

```
const= new Flex('.........');
const microform = flex.microform('card');

const securityCode = microform.createField('securityCode', {maxlength:4});
```

`createToken(options, callback)`{#class-microform-v2_createTokenoptionscallback}  
Request a token using the card data captured in the Microform fields. A successful token creation will receive a transient token as its second callback parameter.  
**Parameter**

| Name     | Type     | Description                                                                                                                                          |
|:---------|:---------|:-----------------------------------------------------------------------------------------------------------------------------------------------------|
| options  | object   | Additional tokenization options.                                                                                                                     |
| callback | callback | Any error will be returned as the first callback parameter. Any successful creation of a token will be returned as a string in the second parameter. |

**Properties**

| Name            | Type   | Attributes         | Description                                                                            |
|:----------------|:-------|:-------------------|:---------------------------------------------------------------------------------------|
| type            | string | \&lt;optional\&gt; | Three-digit card type string. If set, this will override any automatic card detection. |
| expirationMonth | string | \&lt;optional\&gt; | Two-digit month string. Must be padded with leading zeros if single digit.             |
| expirationYear  | string | \&lt;optional\&gt; | Four-digit year string.                                                                |

**Examples**  
*Minimal example omitting all optional parameters.*

```
microform.createToken({}, function(err, token) {
	if (err) {
		console.error(err);
		return;
	}

	console.log('Token successfully created!');
	console.log(token);
});
```

*Override the **cardType** parameter using a select element that is part of your checkout.*

```
// Assumes your checkout has a select element with option values that are  card type codes:
// &lt;select id="cardTypeOverride"&gt;
//   &lt;option value="001"&gt;Visa&lt;/option&gt;
//   &lt;option value="002"&gt;Mastercard&lt;/option&gt;
//   &lt;option value="003"&gt;American Express&lt;/option&gt;
//    etc...
// &lt;/select&gt;

const options = {
	type: document.querySelector('#cardTypeOverride').value
};
microform.createToken(options, function(err, token) {
	// handle errors & token response
});
```

*Handling error scenarios*

```
microform.createToken(options, function(err, token) {
  if (err) {
    switch (err.reason) {
      case 'CREATE_TOKEN_NO_FIELDS_LOADED':
        break;
      case 'CREATE_TOKEN_TIMEOUT':
        break;
      case 'CREATE_TOKEN_NO_FIELDS':
        break;
      case 'CREATE_TOKEN_VALIDATION_PARAMS':
        break;
      case 'CREATE_TOKEN_VALIDATION_FIELDS':
        break;
      case 'CREATE_TOKEN_VALIDATION_SERVERSIDE':
        break;
      case 'CREATE_TOKEN_UNABLE_TO_START':
        break;
      default:
        console.error('Unknown error');
        break;
  } else {
    console.log('Token created: ', token);
  }
});
```

