[英]Woocommerce checkout trigger validation of all fields
I am trying to trigger validation for the whole checkout form in woocommerce and do something based on having validation errors or not.我正在尝试在 woocommerce 中触发对整个结帐表单的验证,并根据是否存在验证错误做一些事情。
Unfortunately I didn't manage to do it.不幸的是我没能做到。 Anyone has any ideas?
任何人有任何想法?
EDIT: To be more specific, on submitting the woocommerce checkout form.编辑:更具体地说,提交 woocommerce 结帐表格。 I want to check if all the shipping fields are valid, but prevent submitting the form because I want to process that form data further (but only if it's valid).
我想检查所有运输字段是否有效,但阻止提交表单,因为我想进一步处理该表单数据(但前提是它有效)。
great hints in the comments.评论中有很好的提示。 Here is the actual working code, to save some time for future people:
这是实际的工作代码,为未来的人节省一些时间:
// Trigger the validation of the fields (you can adjust and pick which fields are validated)
jQuery('.validate-required input, .validate-required select').trigger('validate');
// Get which fields have failed validation
jQuery('.woocommerce-invalid-required-field').each(function(index, element){
console.log(element.id)
})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.