Prevent Item Inserting after sent to ajax insertItem
See original GitHub issueHi, I read issues #95 and #54 and i still don’t know how to put things work.
Here is my scenario: I use in-line grid insertion and I implement onItemInserting
to validate some blank fields. Then, i send data to my service via ajax. In service, i do some validations in database, if true i insert ok, else i have to cancel insertion and alert user.
This is ajax call:
insertItem: function (item) {
$.ajax({type: "POST",url: '@Url.Action("InsertBox", "UnidadeBox")',data: item, dataType: "json"
}).done(function (response) {
if (response.Success){
}
else{
'what i supouse to do here to set value to insertFailed and use on strategies defined below? ' }
});
},
and this is Controller called by ajax:
[HttpPost]
public JsonResult InsertBox(UnidadeBoxViewModel model)
{
try
{
model.Id = _service.Add(box);
var jsonResult = new
{
Success = true,
Model = model
};
return Json(jsonResult, JsonRequestBehavior.AllowGet);
}
catch (Exception error)
{
var jsonResult = new
{
Success = false,
Message = error.InnerException != null ? error.InnerException.Message : error.Message
};
return Json(jsonResult, JsonRequestBehavior.AllowGet);
}
}
I define a finish strategy and its works but i dont know how to declare and put result on ‘insertFailed’!
var origFinishInsert = jsGrid.loadStrategies.DirectLoadingStrategy.prototype.finishInsert;
jsGrid.loadStrategies.DirectLoadingStrategy.prototype.finishInsert = function(insertedItem) {
if(insertFailed) { // define insertFailed on done of delete ajax request in insertFailed of controller
return;
}
origFinishInsert.apply(this, arguments);
}
Please, help! thanks
Issue Analytics
- State:
- Created 8 years ago
- Comments:11 (5 by maintainers)
Top Results From Across the Web
Use AJAX to prevent refresh when adding to a database
After submitting the form you have to use event.preventDefault() $("#submit-insert").click( function(event) { event.
Read more >Disable Edit after Insert in UI for ASP.NET AJAX | Telerik Forums
In my grid, I have a column that I want to show a combobox for on Insert so that the user can select...
Read more >Behavior to use .insertAfter() on load + after each ajax call?
On load it using .insertAfter() to randomly insert that block between view content element in the grid. The problem is it works on...
Read more >PHP AJAX and MySQL - W3Schools
Explanation: When the query is sent from the JavaScript to the PHP file, the following happens: PHP opens a connection to a MySQL...
Read more >Core AJAX Callback Commands - Drupal
The 'insert/after' command instructs the client to use jQuery's after() method to insert the given HTML content after each element matched ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Thank you for the good example. The reason why it happens: insertion is asynchronous, so you need to return a promise, so that finishInsert can be called, when loading is finished.
In your example it could be:
Note: resolving the promise with actually inserted item allows to redefine data on the server and display the actual item.
I need to get the edited value when I click Save button which is out of grid. For Eg : I have 10 rows and 5 columns in each row (2 columns filled and remaining unfilled) When i click a particular row, 3 remaining columns will change into text boxes where i need to enter some values in it.
Now A Save button is placed outside of Grid, So when clicked I need to get the edited values in a list.
Please help out.