Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Kendo UI - Placeholder - Style

I have a Kendo UI datepicker with placeholder data. Here is the HTML:

<input type="text" class="datepicker"' placeholder="yyyy-mm-dd" />

Here is the JavaScript:

var start = $(".datepicker").kendoDatePicker({
        format: "yyyy-MM-dd",
        parseFormats: ["MM/dd/yyyy"],
        change: startChange
    }).data("kendoDatePicker");

The Kendo UI datepicker displays the placeholder data in the same style as user entered data. I would like to style the placeholder data differently. Specifically, I would like the text to be gray and italicized. When user enters data, the style changes to solid black (non-italicized). Any thoughts on how to do this?

like image 859
James Avatar asked Jan 15 '23 10:01

James


2 Answers

Well, placeholder is an HTML5 attibute and isn't specic to Kendo controls. As I understand it Kendo doesn't offer any support for placeholder over what is supported by the browser, and remember that only some browsers support this attribute; IE does not. Anyway, to style the placeholder you'll have to use vendor prefix CSS properties, see here.

like image 105
Stuart Hallows Avatar answered Jan 17 '23 22:01

Stuart Hallows


I use this..it will work on your HTML and you can style it too :)

    <script>
    // This adds 'placeholder' to the items listed in the jQuery .support object. 
    jQuery(function() {
        jQuery.support.placeholder = false;
        test = document.createElement('input');
        if('placeholder' in test) jQuery.support.placeholder = true;
    });
    // This adds placeholder support to browsers that wouldn't otherwise support it. 
    $(function() {
        if(!$.support.placeholder) { 
            var active = document.activeElement;
            $(':text').focus(function () {
                if ($(this).attr('placeholder') != '' && $(this).val() == $(this).attr('placeholder')) {
                    $(this).val('').removeClass('hasPlaceholder');
                }
            }).blur(function () {
                if ($(this).attr('placeholder') != '' && ($(this).val() == '' || $(this).val() == $(this).attr('placeholder'))) {
                    $(this).val($(this).attr('placeholder')).addClass('hasPlaceholder');
                }
            });
            $(':text').blur();
            $(active).focus();
            $('form:eq(0)').submit(function () {
                $(':text.hasPlaceholder').val('');
            });
        }
    });
    </script>
like image 33
Dan Allen Cabrera Pantinople Avatar answered Jan 17 '23 23:01

Dan Allen Cabrera Pantinople