The following example uses getState
to confirm that all provided fields are valid before form submission:
1var form = document.querySelector('#my-sample-form');23 paypal.HostedFields.render({ /* ... */ }).then(function (hostedFieldsInstance) {4 form.addEventListener('submit', function (event) {5 var state = hostedFieldsInstance.getState();6 var formValid = Object.keys(state.fields).every(function (key) {7 return state.fields[key].isValid;8 });910 if (formValid) {11 // Submit hosted fields card data12 hostedFieldsInstance.submit();13 } else {14 // Let the payer know their fields are invalid15 }16 });17 });