Trim search box fields

We are having an issue where users are copying data from another source like excel and pasting it into the search but there is an extra space at the end of the string, so the search results show 0 results. For example a user will paste '[email protected] ' and nothing will show even though '[email protected]' is in the database. Is there any way to automatically trim a search field? 

Thanks!
Anthony

Parents
  • Here is a quick script you can put in the Custom content of the Person search screen. This will trim leading and trailing spaces from any text entered into the fields.

    I have to paste a screenshot as it wouldn't let me add code :-(

  • That will stop you when typing in a name that has an actual space.

    You could trigger the trim() only if the space key has not been hit:

    crm.ready(()=> {
        $('#pers_firtname').on('keyup', (e)=> {
            // trim only if spacebar not hit.
            if (e.keyCode != 32) {
                $('#pers_firtname').val($('#pers_firtname').val().trim());
            }
        });
        // ...
    });

Reply
  • That will stop you when typing in a name that has an actual space.

    You could trigger the trim() only if the space key has not been hit:

    crm.ready(()=> {
        $('#pers_firtname').on('keyup', (e)=> {
            // trim only if spacebar not hit.
            if (e.keyCode != 32) {
                $('#pers_firtname').val($('#pers_firtname').val().trim());
            }
        });
        // ...
    });

Children
No Data