I’m trying to make my forms only do the validation on submit(which it already does by default), I made a hook to push a script to unlist the blur event so that the form can do its default validation but it just doesn’t remove them.
I used the dev pages from ninja forms and marionette docs
https://developer.ninjaforms.com/codex/client-side-field-validation/
most of it works since I can see the fields id when it validates on the console
my hook:
< ? php
namespace App Hooks;
use function add_action;
class NJFormsDisableOnChangeValidation extends Hook {
public $priority = 9;
protected $type = 'filter';
protected $actions = [
'wp_enqueue_scripts'
];
public
function __invoke() {
add_action('wp_footer', function() {
?
>
<
script type = "text/javascript" >
jQuery(document).ready(function($) {
console.log('Script loaded correctly');
var ValidationController = Marionette.Object.extend({
initialize: function() {
console.log('ValidationController init');
var fieldChannel = Backbone.Radio.channel('fields');
var submitChannel = Backbone.Radio.channel('submit');
// Deactivate validations on change and blur
fieldChannel.off('change:modelValue');
fieldChannel.off('blur');
// Maintain validation only in submit
this.listenTo(submitChannel, 'validate:field', this.validate);
console.log('Modified validation events: change and blur disabled..');
},
validate: function(model) {
// Check the field type.
if (1 != model.get_setting('required')) return;
console.log('Validation only in submit executed for the field with ID:', model.get('id'));
}
});
new ValidationController();
}); <
/script> <
? php
});
}
}