how to achieve trimming space as you type in a textfield

book

Article ID: 144897

calendar_today

Updated On:

Products

CA Service Catalog

Issue/Introduction

 


I'm trying to trim spaces from a text field.  Tried using it in the "onKeyUp",   with no luck.   I tried to do with the following JS function code 


 

    trimSpacesfunction (fieldID)

    {

        var hostShortName=ca_fdGetTextFieldValue(ca_fd.formId,fieldID).trim();

        ca_fdSetTextFieldValue(ca_fd.formId,fieldID,hostShortName)

    }

 


 

Cause

The catalog itself is going to trim the leading space and appending space in value of a text field when saving it into the database . With that ,  if you use the JS code above to achieve  trimming as you typing in a text field  here ,  it will not work .  

Environment

Release : 17.2

Component : CA SERVICE CATALOG

Resolution

You should use replace(/\s/g, '') instead of trim()

for example , the code above should be

var hostShortName=ca_fdGetTextFieldValue(ca_fd.formId,fieldID).
replace(/\s/g, '')