Link to home
Start Free TrialLog in
Avatar of Starr Duskk
Starr DuskkFlag for United States of America

asked on

Change Chrome input type date placeholder color?

I am using the standard input type date textbox on Chrome.

        <asp:TextBox ID="txtHireDate" CssClass="stylDOBTextbox" runat="server"></asp:TextBox>

Open in new window


I am setting the attribute type to date in the code behind.
txtHireDate.Attributes("type") = "date"

Open in new window


Right now the place holder text is "mm/dd/yyyy" and the color for the placeholder text is the same as the input text.
I need the placeholder text to be a different color than when the user selects a date.

I have tried these css solutions below and none of them have worked:
input[type="text"]:disabled, input[type="date"]:disabled {
  color: #9A9A9A;
}

input[type="date"]:invalid::-webkit-datetime-edit {
    color: #9A9A9A !important;
}
::-webkit-datetime-edit-day-field:not([aria-valuetext=blank]),
::-webkit-datetime-edit-month-field:not([aria-valuetext]),
::-webkit-datetime-edit-year-field:not([aria-valuetext]) 
{
 color: #9A9A9A !important;
}
input::-webkit-datetime-edit-fields-wrapper > [aria-valuetext=blank], input::-webkit-datetime-edit-fields-wrapper > [aria-valuetext] {
      color: #9A9A9A !important;
}
::placeholder {
    color: #9A9A9A !important;
}

Open in new window

I also tried using javascript to change the color.
 var el = document.getElementsByTagName("input");
    el.onchange = function () {
        if (el.value === '') {
            el.classList.add("testPlaceholder");
        } else {
            el.classList.remove("testPlaceholder");
        }
    }

Open in new window

None of the solutions I found online seem to work. It appears to be a common issue with the Chrome textbox, but I can't seem to find a solution that works.
Avatar of lenamtl
lenamtl
Flag of Canada image

Hi,

I would suggest to use a date plugins like Bootstrap date picker to have control on the form field CSS otherwise it will take the browser default color.

I'm using this one  because it is easy to use and flexible https://github.com/uxsolutions/bootstrap-datepicker

When you rigth click /  inspect the field in Chrome
check the style tab If the field color is not attached to a CSS class it's mean it is the browser default color
Avatar of Starr Duskk

ASKER

Thank you for your suggestion, but the client wants to use default browser textbox type date. I can bring the information you gave me to their attention, but they have rejected similar date plugins in the past.
There are compatibility issues with browser regarding date
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date#Browser_compatibility

This is what they mention on the page
At the moment, the best way to deal with dates in forms in a cross-browser way is to have the user enter the day, month, and year in separate controls, or to use a JavaScript library
ASKER CERTIFIED SOLUTION
Avatar of Starr Duskk
Starr Duskk
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you for the help regarding this! I really appreciate it.
I'm glad you fix it :)