Select Page
Callbacks Documentation
Edit on
Codepen.io

data-validation-callback

An optional JavaScript function you can provide, which must accept a JSON object consisting of an array with field validation results. This makes it easier to display user-friendly field validation error messages.


x
46
 
1
<!--
2
    Configure an add button to add a bogus product to invoke the error.
3
-->
4
<button onclick="recognize();">Add bogus product to cart invoke error</button>
5
6
<!--
7
    DEMO SETUP
8
        - Initialize the Store Builder Library
9
-->
10
<script
11
    id="fsc-api"
12
    src="https://sbl.onfastspring.com/sbl/1.0.2/fastspring-builder.min.js"
13
    type="text/javascript"
14
    data-storefront="fastspringexamples.test.onfastspring.com/popup-fastspringexamples"
15
    data-validation-callback="dataValidationCallback"
16
    >
17
</script>
18
19
<!--
20
    dataValidationCallback
21
        - In this example, it will write the error code and display to the console.
22
-->
23
<script>
24
    function dataValidationCallback(error) {
25
        var arrayLength = error.length;
26
        for(var i = 0; i < arrayLength; i++) {
27
        if(error[i].error) {
28
            console.log("error code: " + error[i].error["code"]);
29
            console.log("error display: " + error[i].error["display"]);
30
        }
31
    }
32
    }
33
    
34
    function recognize() {
35
        fastspring.builder.recognize(
36
            {
37
                "email":"bruce@",
38
                "postalCode":"867-5309"
39
            }
40
        );
41
        fastspring.builder.country("not a valid country");
42
        fastspring.builder.taxId("not a valid tax id");
43
        fastspring.builder.language("not a valid language");
44
        fastspring.builder.promo("not a valid promo code");
45
    }
46
</script>
1
 
1
1
 
1

    Related Topics