dhtmlxCombo backed with dhtmlxDataStore: 2 problems

Hello,

I have a simple form with one dhtmlxCombo backed with dhtmlxDataStore and two buttons. One button is used to validate the form, another one is to popup a new form to add a new item. You can find the working sample here:

http://0x7f.net/dhtmlx/test.html

What I would like to accomplish is to append new item to the combo if’s really appended on the server side. otherwise, ignore it.

Let me explain 2 problems which I discovered so far:

  1. When I add an item to the datastore, it’s added regardless of the response from the server (I send action=“error” in the response)
  2. For a recently appended items, form validation fails.

Any ideas what is wrong with my code?

Below I have put 2 additional questions which I had during the process:

a) Do I relly need a dataProcessor for CRUD operations? Maybe I can only use dhtmlxDataStore object with dataFeed (I do not have clear understanding in which cases can we use dataFeed for datastore).

b) Should I call any cleanup functions for a form which is attached to a window when I use win.close()?

(1) this is expected, you can handler error response with custom code and remove record after receiving “error” response if necessary

(2) new option has not “value” assigned. I see the code which you have used - but it is called just after .add command, and obj has not id property ( as it was not defined by the form ) , also existing code will not update value after id will be changed from dataprocessor callback

(a)
You can work without dataprocessor just to dhtmlxAjax call to server side script, and based on its response - add option to datastore or do not do it.

(b) not necessary, window will destroy all its content ( but you can use win.hide() instead of win.close() and reuse window when necessary, instead of creating new one )

(1) this is expected, you can handler error response with custom code and remove record after receiving “error” response if necessary
clear.

(2) new option has not “value” assigned. I see the code which you have used - but it is called just after .add command, and obj has not id property ( as it was not defined by the form ) , also existing code will not update value after id will be changed from dataprocessor callback

As far as I understand, id is sent to the server side, but seems it’s automatically appended after $init: function {} is called. So I added the following hidden item to the form:

{type: 'hidden', name: 'id', value: new Date().getTime()}

I have also updated onAfterUpdate event handler and set it to:

dp.attachEvent("onAfterUpdate", function(sid, action, tid, tag) { if (action == "error") { ds.remove(tid); dhtmlx.message({type:'alert-error', text:tag.getAttribute('msg')}); } else if (action == "inserted") { var item = ds.item(tid); item.value = tid; ds.update(item); dhtmlx.message({type:'alert', text:tag.getAttribute('msg')}); } });

Now everything seems to ok. What I don’t like here is that I add and remove an item from DS in case of server-side failure. dhtmlxAjax sounds like better approach,

Thanks for your time and great support.

Best Regards,

George

if you will use dhtmlxAjax, but still want to use connector on server side, all what need to be done for inserting operation is the next

dhtmlxAjax.post("connector.php?action=insert", form.getFormData(), function(loader){ //callback var status = loader.xmlDoc.responseText.split("\n"); if (status[0] != "true") error_processing(); success_processing(status[1]); //new id })

Connector support simplified data protocol just for such cases.
docs.dhtmlx.com/doku.php?id=dhtm … rm_changes

Stanislav,

Following your example with dhtmlxAjax throws an error here:

Timestamp: 05/12/2013 08:02:56 PM
Error: [Exception… “‘JavaScript component does not have a method named: “available”’ when calling method: [nsIInputStream::available]” nsresult: “0x80570030 (NS_ERROR_XPC_JSOBJECT_HAS_NO_FUNCTION_NAMED)” location: “JS frame :: 0x7f.net/dhtmlx/lib/dhtmlx.js :: dtmlXMLLoaderObject.prototype.loadXML :: line 12” data: no]
Source File: 0x7f.net/dhtmlx/lib/dhtmlx.js Line: 12

Not sure whether I have to include anything else.

As I use perl on server side, I don’t have much options I guess. I have to reverse engineer your samples and simulate a connector myself.

Thanks for your suggestions.

Best Regards,

George

JavaScript component does not have a method named: “available”
Not quite sure is problem related to dhtmlx at all. As far as I can see, none of dhtmlx components has such method - so error can be produced by some custom code.

I have to reverse engineer your samples and simulate a connector myself.
Connector just generate data feed and provides response as json | xml
If you are using custom code - you can use your own data saving conventions, while server side provides valid json|xml it will be loaded in the component

dhtmlxAjax.post("test.php", JSON.stringify(form.getFormData()), function(loader){
    //callback
    ....
});

JSON.stringify(form.getFormData()) did the trick. Below is a thread which pointed this out.

http://stackoverflow.com/a/15844406

Best Regards,

George