-
Notifications
You must be signed in to change notification settings - Fork 729
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
form record: partial update #405
Comments
Good question. It is not implemented right now, but I have thought of it. Currently there is form.record and form.original. But I will implement it. |
I have looked at it and it is harder then it looks. In the grid it was simpler. The problem starts with nested objects and you can delete nodes, etc. |
I can provide "diff" algorithm.
|
That's would be awesome. Here is the current that I have getChanges: function () {
var differ = function(record, original, result) {
for (var i in record) {
if (typeof record[i] == "object") {
result[i] = differ(record[i], original[i] || {}, {});
if (!result[i] || $.isEmptyObject(result[i])) delete result[i];
} else if (record[i] != original[i]) {
result[i] = record[i];
}
}
return result;
}
return differ(this.record, this.original, {});
} One problem to fix, how do you do diff if some records were deleted. Lets say form has enum, I need to mark that some records were deleted, and some where added. |
Returns changed values, only null value represents deleted property.
diff function
|
Did you get it from underscore? Is there anyway to shorten it, looks long? Belos is real form data with drop down, enum, file, etc controls. {
"field.text":"some text",
"field.textarea":"more text",
"field.date":"1/15/2014",
"field.time":"10:11 am",
"field.color":"999999",
"field.list":{
"id":0,
"text":"Pickle, Susan"
},
"field.combo":{
"id":1,
"text":"Item 1"
},
"field.enum":[
{
"id":"1",
"text":"item 1"
},
{
"id":2,
"text":"item 2"
}
],
"field.file":[
{
"name":"file.txt",
"size":3033,
"type":"text",
"modified":"1/1/2014"
}
],
"field.email":"[email protected]",
"field.password":"pass",
"field.int":"10",
"field.float":"20",
"field.money":30,
"field.currency":40,
"field.percent":50,
"field.alpha":"60",
"field.select":3,
"field.check":33
} Modified: {
"field.text":"some text - chanes",
"field.textarea":"more text",
"field.date":"1/15/2014",
"field.time":"10:11 am",
"field.color":"999999",
"field.list":{
"id":1,
"text":"Adams, John",
"hidden":true
},
"field.combo":"",
"field.enum":[
{
"id":"1",
"text":"item 1"
},
{
"id":"Cruz, Steve",
"text":"Cruz, Steve"
}
],
"field.file":[
],
"field.email":"[email protected]",
"field.password":"pass",
"field.int":"10",
"field.float":"20",
"field.money":30,
"field.currency":40,
"field.percent":50,
"field.alpha":"60",
"field.select":3,
"field.check":33
} can you diff it? |
Here is the result.
I think that
|
Thanks for your help. I think there are some particularities in how diff should work. For example for enum fields if I have a structure "field.enum":[
{
"id":"1",
"text":"item 1"
},
{
"id":"Cruz, Steve",
"text":"Cruz, Steve"
}
], and if I delete one item, it will change to "field.enum":[
{
"id":"1",
"text":"item 1"
}
], And diff should produce this: "field.enum":[
{
"id":"1",
"text":"item 1"
},
{
"id":"Cruz, Steve",
"text": null
}
], or maybe "field.enum":[
{
"id":"1",
"text":"item 1"
},
deleted['Cruz Steve']
], I think enum is the only non-standard field (and file type too). For all other it should be simple. |
Is there possible to send to the server only changed fields in payload?
Changed fields = changed object properties
Possible implementations
Grid support similar functionality via grid.getChanges() - return changed fields.
Nice to have :)
The text was updated successfully, but these errors were encountered: