[RESOLVED] Dynamically Capitalize String

Hi community!

I have a little issue that is probably a simple fix for any experienced dev!

I have a text field which users type a unique Cost Centre number and it works great! The only issue I have is that I want the Value to be automatically capitalised after the user has interacted with the field.

Here is how I want the format to be: A000003
Here is an example of when someone just types a number in without using Caps Lock: a000003

Here is my code:

 var ccexists = false;
fd.field('Cost_Centre').validators.push({
        name: '',
        error: "Please enter a valid 7 digit Cost Centre Code",
        validate: function() {
            return ccexists;
        }
  });
  
  fd.field('Cost_Centre').$on('change', function(value){
    validateCC(value);
});

//This function is doing a Lookup to the Org Hierarchy SharePoint list
function validateCC(value){
//validate the entered value
if ((/^[A-Za-z]\d{6}$/).test(value)) {
  var filter = "Cost_x0020_Centre eq '" + value + "'";
  pnp.sp.web.lists.getByTitle("OrgHierarchy").items.filter(filter).getAll().then(function(items){
    if(items.length > 0){
    $($(fd.field('Cost_Centre').$el).find('input')[0]).attr('style', 'border-color: #6CEE5A; box-shadow: 0 0 5px #6CEE5A;');
    ccexists = true;
    }

  });
}    

else{
    $($(fd.field('Cost_Centre').$el).find('input')[0]).attr('style', 'border-color:#ff0000; box-shadow: 0 0 5px #ff0000; Color:#ff0000;');
    ccexists = false;
}
};

Hello @DryChips,

You can use the toUpperCase() method for this.

fd.field('Title').$on('change', function(value) {
    fd.field('Title').value = value.toUpperCase()
})
1 Like

Thank you Margarita. Works great!

1 Like