@Francois I agree, it is unfortunate that there’s no method of doing so natively.
The reason its not working for you example is because name fields are split into separate inputs, so you have to target those inputs differently.
Here is the updated code to cover any inputs in your name field (i.e. first, middle, last, etc), replace field_x
with your name field:
$(document).on('knack-view-render.any', function(event, scene) {
// Prevent whitespace input in a name field with key 'field_58'
$('#kn-input-field_xx input').on('input', function() {
this.value = this.value.replace(/\s/g, '');
});
});
If you wanted to only target one of the fields (e.g. the first name), you can swap out the event handler to this:
$('#kn-input-field_60 #first').on('input', function() {