This is a migrated thread and some comments may be shown as answers.

Add css class dynamically to kendo controls.

2 Answers 1426 Views
Date/Time Pickers
This is a migrated thread and some comments may be shown as answers.
NEO
Top achievements
Rank 1
NEO asked on 07 May 2013, 03:29 AM
Hello,

I am trying to add the css class to the kendo controls based on some validations. I tried as given in the below code but its not applying. Please suggest me how i can achieve this.

var datePicker = $("#SampleDatePicker").data("kendoDatePicker");
datePicker.addClass('error-Border');

Thanks and Regards,
Ravi

2 Answers, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 07 May 2013, 07:55 AM
Hi Ravi,

In order to achieve the desired outcome you should add the CSS class to the HTML element from which the Kendo UI widget is initialized. I.e.:

$("#SampleDatePicker").addClass('error-Border');

Kind regards,

Iliana Nikolova
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Paweł Korczak
Top achievements
Rank 1
Iron
answered on 04 Nov 2022, 02:30 PM

How do I add a class?
What should it look like?

this.addClass ( 'invalid')
kendoNumericTextBox({ label : "  price", format : "n2", decimals : 2 , 
		change: function() {
		if ( this.value() == 0 ) { this.addClass ( 'invalid') } else { this.removeClass ( 'invalid') } 
	} // ---
 }


Paweł 

Georgi Denchev
Telerik team
commented on 08 Nov 2022, 09:48 AM

Hi, Paweł,

The NumericTextBox consists of several elements so it depends on what you expect the final result to look like.

There components consists of two inputs. One input is shown when the input is not focused. The second input is shown when you click inside the element.

To add a class to the "unfocused" input, use the following snippet:

this._text.addClass("invalid");

To add class to the "focused" input, use the following snippet:

this.element.addClass("invalid");

Dojo

I've prepared a Dojo example where you can see the difference:

https://dojo.telerik.com/@gdenchev/oxeQUDiP 

Best Regards,

Georgi

Tags
Date/Time Pickers
Asked by
NEO
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Paweł Korczak
Top achievements
Rank 1
Iron
Share this question
or