Once upon a time, there was two table in a mysql database called people and users. There is 1-n relationship between them. A user always linked into a people and a people could have 0 or one user account. There is a multiview(3 pages) with a grid and two forms in my app. The grid contains a list of people recorded into the people table (1st page). On a second page there is a form which linked into the grid editing people details. It works correctly. On the third page would be an other form which contains text fields for username and user level (defining the user rights) etc. If people has user account the form would be filled by data from the user table, if not, the form would be empty.
How should be implement the relationship between the user form and the people grid?
In my opinion the solutions that is used in the following sample will do:
dhtmlxTouch_v10_111114/samples/technical/server/01_loading/11_list_to_form_server.html
You need to bind the people list with account form:
$$(‘myform’).bind(‘mylist’);
and define dataFeed property in the form config:
…
{view:“form”, id:“myform”, dataFeed:“accountdata.php”, elements:[…]},
…
When the cursor (selected item) in the list is changed, the request with “id” parameter (item id from people list) will be sent to teh server (dataFeed url).
It’s OK, but I read somewhere in the documentation of dhx.DataProcessor about if I want to insert record into connected table the key must be autoinc field. So the users table looks like this:
user_ID int(11) NOT NULL auto_increment,
people_ID int(11) NOT NULL,
username varchar(20) collate utf8_unicode_ci NOT NULL,
passwd varchar(40) collate utf8_unicode_ci NOT NULL,
level int(2) NOT NULL,
PRIMARY KEY (user_ID)
So the ID which will send is only foreign key.
dsUsrRights.php looks like this:
Case 1: there is a record in the database and dsMyform.php returns with requested data in JSON form. In this case the code above works correctly, the form showing correct data.
Case 2: there isn’t any record in the database which requested and dsMyform.php returns: [] . I wait in this case the myform should be empty according to clear() method, but it contains last succesfully fetched data.
How can I clear the form when it gets empty data from its datasource?
I think I walking in a right direction but I will need some help Thank you!
The form is on third page of a multiview so I think it is loaded only once during the loading of the whole page. So I must clear it’s content and try loading current data if exist or leave empty before showing it. The grid’s onafterselect event seems to be suitable for this.
+-----------------------------------------------------------------+
| Multiview contains 3 views |
+----------1------------+----------2-----------+--------3---------+
| myGrid contains few | frmGrid contains | myform contains |
| important information | detailed infromation | the login data |
| about employes | of selected employee | if the selected |
| | and can modify it's | employee can log |
| | data (binded to grid)| in to the site |
+-----------------------+----------------------+------------------+
The problem is that just few employee can login to the site. So myform often gets empty result from it’s datasource. In this case would highly desirable appearing blank form.
But after some investigation… I found a solution
I can check the response immedietly after loading. Just should call the load method of the form in different way:
$$("mygrid").attachEvent("onafterselect",function(id){
$$('myform').load('dsMyform.php?action=get&id='+id, function(text,xml,http_request){
if (text =="[]") $$('myform').clear();
});
});
It does exactly what I want.
I have only one more question:
I dont know why, but it looks the load method sets the form values back to last successful loaded data in case of empty response. Is this a bug?
We have tried to reproduced the problem once again - it is not reproduced.
clear() removes all values from a form. And load() method sets only loaded data. Please make sure that response is correct and contains desired values.
According to the password stored as MD5HASH in the database that isn’t in the response. So those two fields will be use for defining or changing the password but never will display that.