skip to Main Content

I have a JS where I can detect if uppercase is being entered, but I’m unable to convert the text text to lower case. i have used CSS text-transform: lowercase; but this shows that it’s lower but once submitted, it shows the text as normal (original format).
I have tried with jquery toLowerCase(); but I don’t know what I have missed here coz it didn’t work.
this is my script,

  const setup = function(fieldSelector) {
    const field = $(fieldSelector);
    const upperCase= new RegExp('[A-Z]');
    const applyStyle = function() {
      if (field.val().match(upperCase)) {
        field.val().toLowerCase();
      } else {
        field.val();
      }
    };
    field.on('change', applyStyle);
    applyStyle();
  }
  // Note: Change the ID according to the custom field you want to target.
  setup('#issue_custom_field_values_17');
});

this code is used for redmine "View customize plugin"

4

Answers


  1. Uppercase doesn’t change the original string. Try assigning a new variable for your uppercase and see if it works!

    Login or Signup to reply.
  2. I think this should do the job for you

    $('input').keyup(function(){
     let val = $(this).val().toLowerCase()
     $(this).val(val)
    })
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <input type="text">
    Login or Signup to reply.
  3. try this

    const char = string.charAt(field.val());
    const isUpperCaseLetter = (/[A-Z]/.test(char));
    
    Login or Signup to reply.
  4. You can set the value of the field to the new lowercase value on change

     const setup = function(fieldSelector) {
            const field = $(fieldSelector);
            const upperCase= new RegExp('[A-Z]');
            // Here's the change
            const applyStyle = function() {
             field.val( field.val().toLowerCase() )
            };
            field.on('change', applyStyle);
            applyStyle();
          }
          // Note: Change the ID according to the custom field you want to target.
          setup('#issue_custom_field_values_17');
        });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search