Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

Version 1 Next »

The SDK includes built-in validation that prevents form submission if fields are invalid.

View all the emitted events here.

Default Behavior

  • The form will not submit unless all fields pass validation

  • Invalid fields will display in red (unless overridden in style properties)

  • Validation occurs on the input blurevent, as well as after the submit button is clicked.

Custom Validation Handling

For more control over validation, you have two options:

  1. Validation Callback:

function customValidate(message) {
    if (!message.success) {
        // Handle invalid field
        showError(message.message);
    }
}

Netvalve.initTokenFields({
    formId: 'paymentForm',
    onValidate: customValidate
});
  1. Custom Event Handler

Event Name: validation

window.addEventListener('validation', (event) => {
  const message = event.detail;
  // Handle validation result
});

The message has this object structure:

  {
      type: 'validation',
      fieldName: 'cardNumber' | 'cardCvv' | 'cardExpiry',
      success: boolean,
      message: string,
      paymentToken: string
  }

View the full message structure.

Handling Failed Tokenization

In rare cases where tokenization fails on the Netvalve server, the form will not submit even if the validation . You can handle these cases using the tokenization event:

Event Name: tokenization

window.addEventListener('tokenization', (event) => {
        const result = event.detail;
        // result structure:
        {
            type: 'tokenization',
            fieldName: 'cardNumber' | 'cardCvv' | 'cardExpiry',
            success: boolean,
            message: string,
            paymentToken: string
        }

        if (!result.success) {
            showError('Failed to process card details.');
        }
});

See Also

  • No labels