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

Is it possible to remove "k-textbox" class from MaskedTextBox?

7 Answers 830 Views
MaskedTextBox
This is a migrated thread and some comments may be shown as answers.
Alex
Top achievements
Rank 1
Alex asked on 07 Jan 2016, 06:06 AM

Hello everyone,

 

Is it possible to remove the "k-textbox" class from MaskedTextBox? I have my own Bootstrap/Material Design input class.

 

<div class="form-group form-group-material-light-blue">
    @(Html.Kendo().MaskedTextBox()
          .Name("phone_number")
          .Mask("(999) 000-000-000")
          .HtmlAttributes(new {@class = "form-control floating-label mdc-text-grey-700"})
          )
</div>

But still after the page renders "k-textbox" gets added automatically.

 

Please advice,

Alex

 

7 Answers, 1 is accepted

Sort by
0
Iliana Dyankova
Telerik team
answered on 08 Jan 2016, 04:30 PM
Hello Alex,

You could achieve this by using the jQuery removeClass method:
$("#phone_number").removeClass("k-textbox");


Regards,
Iliana Nikolova
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 09 Jan 2016, 02:13 AM

Hello Iliana,

Thanks for your reply however when I try the above mentioned method for Grid Popup it doesn't apply to the MaskedTextbox. Because that MaskedTextbox is located inside the popup (for create and edit).

I tried the same thing outside the Grid (as HTML razor) and it worked fine. Please see my attached image as it explains everything. I even try to apply my own checkbox but again it doesn't work as well.

Please advice,

Alex

0
Accepted
Iliana Dyankova
Telerik team
answered on 12 Jan 2016, 02:45 PM
Hi Alex,

In this case you should remove the k-textbox in the Grid edit event
@(Html.Kendo().Grid<Kendo.Mvc.Examples.Models.ProductViewModel>()
   .Name("grid")
   //....
   .Events(ev=>ev.Edit("onEdit"))
)
 
<script>
function onEdit()
   $("#phone_number").removeClass("k-textbox");
}
</script>


Regards,
Iliana Nikolova
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 14 Jan 2016, 01:41 PM

Hello Iliana,

Thank you so much for your quick support.

I think it's worth mentioning that using MaskedTextBox inside Grid editor might be sometimes problematic. Because when I was binding to ViewModel there was no value inside that box so I neded

@model string

@{
    var attemptedValue = "";
    var modelStateForValue = Html.ViewData.ModelState[Html.IdForModel().ToString()];
    if (modelStateForValue != null)
    {
        attemptedValue = modelStateForValue.Value.AttemptedValue;
    }
}

<div class="form-group form-group-material-light-blue">
    @(Html.Kendo()
          .MaskedTextBox()
         .Name(Html.IdForModel().ToString())
          .Mask("(999)-000-000-000")
          .Value((!string.IsNullOrEmpty(attemptedValue)) ? attemptedValue : "")
          .HtmlAttributes(new { @class = "form-control floating-label mdc-text-grey-700" })
    )
</div>

 

<script>

function onEdit() {
          $("#Phone").removeClass("k-textbox");
        };

</script>

Note: #Phone is the name of the field inside ViewModel, you can use anything else.

 

Best,

Alex

0
Alex
Top achievements
Rank 1
answered on 14 Jan 2016, 01:44 PM

I found some typos and incomplete sentence in my last message.

"Because when I was binding to ViewModel there was no value inside that box so I needed to do the following:"

Sorry for that :)

0
Iliana Dyankova
Telerik team
answered on 18 Jan 2016, 09:24 AM
Hello Alex,

From the provided code snippet it appears the desired outcome is achieved - can we consider this case resolved?

Regards,
Iliana Nikolova
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Alex
Top achievements
Rank 1
answered on 18 Jan 2016, 02:23 PM

Hello Iliana,

Yes, please mark this as resolved.

Thanks,
Alex

Tags
MaskedTextBox
Asked by
Alex
Top achievements
Rank 1
Answers by
Iliana Dyankova
Telerik team
Alex
Top achievements
Rank 1
Share this question
or