Inline Edit not saving data when Server Side Validation entered
Inline Edit not saving data when Server Side Validation entered
I have a table I'm updating inline. I added validation in the controller and it works when adding a new user. It also shows the error in the inline editor if it is invalid- but, it won't save it. No errors are thrown either. I can put the original value in and it acts like it saves that value - but anything different it just sits there with the submit button still visible.
Is there something different I have to do when adding server side validation?
$('#webuser').on('click', 'tbody td:not(:first-child)', function (e) {
cell = this;
idx = table.cell(this).index();
//skip columns
if (idx.column == 4 || idx.column == 5 || idx.column == 6) {
return;
}
//Skip checkbox controls
if ($(this).hasClass('dt-body-center')) {
return;
}
editor.inline(this, {
buttons: {
label: '>', fn: function () {
if (idx.column == 3)
{
var hsh = CreateHash(editor.field('Password').val());
editor.field('PasswordHash').val(hsh);
}
this.submit();
} }
});
});
[HttpGet, HttpPost, Route("api/webuser/{clientname?}")]
public IHttpActionResult WebUser(string clientname)
{
var request = HttpContext.Current.Request;
string dbtype = "sqlserver";
string conn = DBServer.Replace("dbname", clientname);
DataTables.DtResponse response = new DtResponse();
try
{
using (var db = new Database(dbtype, conn))
{
response = new Editor(db, "tblIPadUsers", "ipadUserID")
.Model<tblIpadUser>()
.TryCatch(true)
.Field(new Field("ipadUserID").Set(false))
.Field(new Field("FullName").Validator(Validation.Required(new ValidationOpts { Message = "This field must be entered." })))
.Field(new Field("UserName").Validator(Validation.MinMaxLen(8, 50, new ValidationOpts { Message = "UserName must be between 8 and 50 characters long.This field must be entered." }))
.Validator(Validation.Required(new ValidationOpts { Message = "This field must be entered." }))
.Validator((val, d, host) => Convert.ToString(val).Contains(" ") ? "Username must not contain spaces" : null))
.Field(new Field("Password").Validator(Validation.MinMaxLen(8, 50, new ValidationOpts { Message = "Password must be between 8 and 50 characters long.This field must be entered." }))
.Validator(Validation.Required(new ValidationOpts { Message = "This field must be entered." }))
.Validator((val, d, host) => Convert.ToString(val).Contains(" ") ? "Username must not contain spaces" : null))
.Field(new Field("PasswordHash"))
.Field(new Field("LockOut"))
.Process(request)
.Data();
}
}
catch (Exception ex)
{
ErrorSignal.FromCurrentContext().Raise(ex);
}
return Json(response);
}
Thanks!
This question has an accepted answers - jump to answer
Answers
Hi,
Could you use your browser's developer tools to check what the JSON response from the server is? I suspect there might be another field which it is reporting in error (that isn't shown in inline editing since it assumes the other fields are valid!).
Regards,
Allan
Here is the response after trying to inline edit/save one of the tables. (I picked a smaller one, not doing as much)
fail
When I take out the validation and edit the same field:
success
Since it is erroring on the other fields because it isn't submitting all of them at once. How do I modify it to edit one field at a time for the inline edit or send them all- and also have them all for the New record?
Could you add:
to the object that you pass into the second parameter for
inline()
? That will cause Editor to submit all fields.The other option is to modify the validation options so that they are only applied when these data is actually submitted.
Allan
GREAT!! Thank you!
I tried it as an inline param and it didn't seem to make a difference. But it worked when I put it as a formOption!