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

e.model.isNew()

2 Answers 1404 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Elliott
Top achievements
Rank 1
Elliott asked on 29 Oct 2013, 05:04 PM
Hi,

I am using the e.model.isNew() to change the Title of the popup depending on whether Edit or Save is pressed.
That's working fine, I am however having an issue with then pressing the edit button to the added item.
The pop up is shown but with "Add", not "Edit" as the title.

If I refresh the page then it works as expected.

Code:
function onEdit(e) {
        if (e.model.isNew()) {
            // add
            $(".k-window-title").text("Add");
        } else {
            // edit
            $(".k-window-title").text("Edit");
        }

    }

Is there a way on the save event to specify that the model is no longer new?

    function onSave(e) {
        // set the model no longer as new ??
        
    }

2 Answers, 1 is accepted

Sort by
0
Ignacio
Top achievements
Rank 1
answered on 29 Oct 2013, 07:10 PM
The isNew method returns true or false depending on the id value of that model. (docs)
If the id is still set to the default value then it will assume it is a New Model.

Are you doing something (probably backend side) to save this item into a database? that will usually auto-generate an id, so you can use that to assign to your client side js model.


Hope that helps.
0
Elliott
Top achievements
Rank 1
answered on 29 Oct 2013, 08:16 PM
Worked like a charm.

Thanks!
Tags
Grid
Asked by
Elliott
Top achievements
Rank 1
Answers by
Ignacio
Top achievements
Rank 1
Elliott
Top achievements
Rank 1
Share this question
or