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

Popup editor issues

3 Answers 318 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sarvesh
Top achievements
Rank 1
Sarvesh asked on 16 May 2012, 12:19 PM
Hi,

I am using the grids popup edit mode and below are the issues that i am facing.

1) The popup title is "Edit" irrespective of whether i am adding a new record or editing. How do i change the title to "Create" when i am adding a new record.
2) I want one of the field to be disabled on edit but enabled while adding the record. If i set the fields editable flag to false, the field is disabled even while adding a record.

Regards,
Sarvesh

3 Answers, 1 is accepted

Sort by
0
Alexander Valchev
Telerik team
answered on 18 May 2012, 09:23 AM
Hello Sarvesh,

This functionality is not supported out of the box, but you can easily achieve it with a few lines of code.
  1. Hook up to the click event of the add new record button ( .k-grid-add ) and set a flag variable to true.
  2. Hook up to the edit event of the grid and perform changes to the editor window.
  3. Set the flag back to false.
The suitable way to set a new window title is through the title method, the editor inputs could be found in e.container element and enabled/disabled through jQuery.

$(".k-grid-add").on("click", function(e) {
    isCreating = true;
});
 
//grid edit event
 
edit: function(e) {
    if(isCreating) {
         
        //KendoUI v.2012.1.515
        e.container.kendoWindow("title", "Add new record")
        //KendoUI v.2012.1.322
        /*
        var window = e.container.data("kendoWindow");
        window.title("Add new record");
        */

        //reset the flag
        isCreating = false;
    }
}

I hope this information will help.

Kind regards,
Alexander Valchev
the Telerik team
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
0
Sarvesh
Top achievements
Rank 1
answered on 18 May 2012, 11:32 AM
Hi,

Thanks for the solution. Managed to get the title to change but facing strange issue while changing button text. Below is my edit handler.

function editFunc(e) {
if (e.model.FirstName != "") {
//Edit Mode
}
else {
//Create Mode
$("div.k-window-content").parent().children("div.k-window-titlebar").children("span.k-window-title").text("Create");
var node = $("div .k-window-content a.k-button:first").contents().filter(isTextNode).replaceWith(document.createTextNode("Create"));
}
}

function isTextNode(){
   return (this.nodeType === 3);
}

When i click on add record for the first time the text for the "Update" button is changed to "Create". If i cancel the popup and click on add record again the button text does not change to "Create".

Regards,
Sarvesh
0
Alexander Valchev
Telerik team
answered on 23 May 2012, 09:16 AM
Hello Sarvesh,

I believe the problem is not directly related to kendo grid component - it is caused by the way you determine which action is being performed (creating or editing). It seems that after cancelling the popup and clicking on the "Add new record" button for a second time the logic in your edit function does not detect the create mode.

In the attached file you will find an example that shows one possible implementation of this case.
I hope this helps.

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