#nikhil24 - field validation
1 messages · Page 1 of 1 (latest)
Whats the context for this? Can you rephrase your questions or explain a bit more about what you're trying to do?
@hollow hedge When I enter value in CVC field and when i empty the values in CVC field, they have to validate saying that CVC field is empty
Could you please help me with that?
Ah, gotcha
for this, you probably want to listen to the change events emitted by each element and inspect the empty attribute. eg, for a cvc element:
https://stripe.com/docs/js/element/events/on_change?type=cardCvcElement#element_on_change-handler-empty
Complete reference documentation for the Stripe JavaScript SDK.
cardCvcElement.on('change', function(event) {
if (event.error) {
// show validation to customer
console.log("Field is empty");
}
});
When i write this code and add values in cvc and remove the values, even console.log value is not showing up 😦
Did you get this working?
Instead of event.error should I be using proper condition to check?
Well when you log the entire event what do you see?
I m so sorry, how do we log entire event
I mean just use console log for every event unconditionally, and log the whole event object
cardCvcElement.on('change', function(event) {
console.log({event});
});
eg
When i enter for postal code i am getting this
Currently postal code is not validating properly
what part of that is not what you expect?
you were asking about empty CVC before, so this postal code question is new
What are you trying to do, exactly?
Its just a example i gave for cvc
Actually postal code is not validating correctly
that's the issue
error is want i want to see, as i have entered partial postal code
Currently i have added just 1 digit in postal code, it has to validate saying invalid postal code or something like that
How are you managing that element? THat's not supported in split mode using your own postal code field as far as i know. You'd implement your own validation on the. value.
If you're using the combined card element with auto-validating postal code, for example, there are some errors that are useful about this.