This is a migrated thread and some comments may be shown as answers.
Duplicating textbox
2 Answers 46 Views
This is a migrated thread and some comments may be shown as answers.
andy
Top achievements
Rank 1
andy asked on 23 Apr 2012, 05:32 PM
Everytime I fire this command a new instance of the Kendo numerictextbox widget span appears. It is tied to the same element though. Is there an inbuilt event or method that checks for existing numerictextbox widget span and doesn't add another?

$("#MROEveryHourNum").kendoNumericTextBox({
                value: 1,
                min: 0,
                max: 51,
                step: 1,
                format: "#",
                decimals: 0
            });

Thanks

2 Answers, 1 is accepted

Sort by
0
usman
Top achievements
Rank 1
answered on 03 Jan 2014, 05:50 PM
I am facing the same issue. I have a grid and in a cell of a row i have simple text box. When data gets bound i use the following code to convert to text box like this:

Below is the simple text box template used with templated column:
<input class="NumericInteger" type="text" style="width:130px;" onchange=''grid_LeaveAccrual_textbox_onchange("LeaveAccrual","EmployeePayrollLeaveDistributionDataView", this)'' value="#=LeaveAccrual == null ? "0" : LeaveAccrual #" />

 var grid = $("#Grid").data("kendoGrid");
 var gridData = grid.dataSource.data();
//row databound event
grid.tbody.find('.NumericInteger').each(function () {            
            $(this).kendoNumericTextBox();
        });

where .NumericInteger is the css class i have attached with simple text box.

There are two issues:
1- Change event gets fired twice.
2- If i tried to iteration grid data and update the textbox value using below code, it adds the textbox span multiple times. In some ajax call, i am trying to update cells with numeric textbox data:

 var grid = $("#Grid").data("kendoGrid");
                    var gridData = grid.dataSource.data();

                    for (var i = 0; i < result.LeaveDistribution.length; i++) {
                        var item = result.LeaveDistribution[i];

                        for (var j = 0; j < gridData.length; j++) {
                            if (item.Text == gridData[j].PayrollPeriodId) {
                                gridData[j].LeaveAccrual = item.Value;

                                var uid = gridData[j].uid;
                                //updating numeric text box
                                var row = $("#EmployeePayrollLeaveDistributionDataView").data("kendoGrid").tbody.find("tr[data-uid='" + uid + "']");
                                var $ntb = row.find('.NumericInteger').kendoNumericTextBox().data("kendoNumericTextBox");
                                $ntb.value(item.Value);
                                break;
                            }
                        }
                    }
Please see attachment whats happening
0
Alexander Valchev
Telerik team
answered on 07 Jan 2014, 12:40 PM
Hi Usman,

The issue #2 occurs because you are re-initializing the widget at the following line:
var $ntb = row.find('.NumericInteger').kendoNumericTextBox().data("kendoNumericTextBox");

Removing the code marked in red should solve the problem.
I believe that this might be the reason for issue #1 as well.

Regards,
Alexander Valchev
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Asked by
andy
Top achievements
Rank 1
Answers by
usman
Top achievements
Rank 1
Alexander Valchev
Telerik team
Share this question
or