A place for users and developers of the Xataface to discuss and receive support.
by tnorbut13 » Thu Apr 23, 2009 7:53 am
Hello all.
I am a newbie when it comes to Xataface and am trying to develop an app. I have come across an issue that I'm not sure how to handle. Given the flexibility of Xataface, I'm sure that something can be done to fix it but I don't know where to begin.
When I am trying to add an existing related record to a record, the default method of pulling the data is a list field. I would like to change this to an autocomplete field like the yui_autocomplete? widget.
Where do I look to make this change? Also, is it possible for it to be autocomplete on one related tab, but a list on another?
Thank you in advance for your help!
-
tnorbut13
-
- Posts: 36
- Joined: Thu Apr 23, 2009 7:46 am
- Location: Chicago, IL
by fongchun » Thu Apr 23, 2009 9:05 am
If you go to the wiki page, in the widget:type [ur="http://xataface.com/wiki/widget%3Atype"l]page [/url]it tells you all the different possible form elements you can use for a particular field.
The one you want is yui_autocomplete. All you have to do is go into your fields.ini file for that delegate class and add the widget:type=yui_autocomplete attribtue to the field you are interested. Also remember you need a vocabulary set for that field to work.
-
fongchun
-
- Posts: 30
- Joined: Sun Aug 03, 2008 12:23 am
- Location: Vancouver, BC
by tnorbut13 » Thu Apr 23, 2009 9:10 am
I understand where to find the widget. My problem is I don't know where in the application to apply a delegate class for the related records.
Here's the scenario:
I have table ABC and table XYZ is a related table. When I click on the Details section of ABC, I can navigate to add a related record from XYZ. It's this form, the one where I add a related record from XYZ table, that I can't find. Where is this and how do I customize it?
-
tnorbut13
-
- Posts: 36
- Joined: Thu Apr 23, 2009 7:46 am
- Location: Chicago, IL
by fongchun » Thu Apr 23, 2009 9:43 am
Related records are just a separate table itself. So you would apply the delegate class to that table. For example:
tables/ABC/ would have an ABC.php (delegate class)
tables/XYZ/ would have an XYZ.php (delegate class)
And some in the tables/XYZ/ folder you would have another file called fields.ini which has the attributes that I earlier listed.
Hope that helps.
Note: You have to add this delegate class yourself. Xataface doesn't create one for you.
-
fongchun
-
- Posts: 30
- Joined: Sun Aug 03, 2008 12:23 am
- Location: Vancouver, BC
by tnorbut13 » Thu Apr 23, 2009 9:47 am
Clarifies it somewhat, but here is what happens when I try that.
Added yuiautocomplete to fields.ini under XYZ folder. Did not do delegate class (maybe that's where I went wrong, dont' know).
The yuiautocomplete works when I go to the regular tab for the table, but when I go to the related record tab under the ABC table for XYZ, it still is a list.
What am I missing?
-
tnorbut13
-
- Posts: 36
- Joined: Thu Apr 23, 2009 7:46 am
- Location: Chicago, IL
by fongchun » Thu Apr 23, 2009 9:57 am
Can you print the code you are using. Give me your fields.ini for XYZ delegate class, and the valuelist.ini file (I am assuming you are using a vocabulary) for this.
Make sure your valuelist.ini file is in the XYZ delegate class folder.
Note: One more question, is the field you are trying to make auto complete the primary key field of the parent table and the foreign key field of the related table?
-
fongchun
-
- Posts: 30
- Joined: Sun Aug 03, 2008 12:23 am
- Location: Vancouver, BC
by tnorbut13 » Thu Apr 23, 2009 10:13 am
fields.ini
[Sales_Name]
widget:type = yui_autocomplete
vocabulary = Sales_Name
Valuelist.ini
[Sales_Name]
__sql__ = "select Sales_ID, Sales_Name from Sales"
Now on the related record it does not display the Sales Name under the record. I'm assuming this is because of the Sales_ID, Sales_Name select.
More importantly, the add an existing related record is still a list, not an autocomplete.
If I add a 'new related record' it is autocomplete.
-
tnorbut13
-
- Posts: 36
- Joined: Thu Apr 23, 2009 7:46 am
- Location: Chicago, IL
by fongchun » Thu Apr 23, 2009 10:28 am
I think the problem isn't a problem at all. I just don't think the feature for doing autocomplete in existing record form is actually implemented. Because you can do it in add new related record is prove you have it setup properly.
This feature will probably be released in the future.
-
fongchun
-
- Posts: 30
- Joined: Sun Aug 03, 2008 12:23 am
- Location: Vancouver, BC
by tnorbut13 » Thu Apr 23, 2009 11:29 am
Ok. While I'm on this topic though...I'm looking to do Autocomplete on a field and have the corresponding ID # populate into it's field as well. How would I do this?
-
tnorbut13
-
- Posts: 36
- Joined: Thu Apr 23, 2009 7:46 am
- Location: Chicago, IL
by fongchun » Thu Apr 23, 2009 12:42 pm
I am assuming you mean for the sql statement
__sql__ = "select Sales_ID, Sales_Name from Sales"
You want the autocomplete to show the Sales_ID and the Sales_Name? I am actually not sure how to do.
Hopefully Steve (creator of Xataface) can answer that question.
-
fongchun
-
- Posts: 30
- Joined: Sun Aug 03, 2008 12:23 am
- Location: Vancouver, BC
by shannah » Tue Apr 28, 2009 12:22 pm
As far as I recall, the autocomplete widgets for xataface (autocomplete and yui_autocomplete) don't work for storing a different ID than the value shown (they are basically for strings only).
However, you could rig something up that would allow you to edit as text, then convert to an ID.
Xataface supports the following methods to "filter" values as they are loaded to and from the widgets of an edit form:
xxx__pullValue()
and
xxx__pushValue()
where 'xxx' is the name of the field. The __pullValue() method is meant to "pull" the field value from a record as it should be displayed in a form field.
The __pushValue() method is meant to "push" the field value back into a record (from a widget).
Here's a simple example:
- Code: Select all
function employerid__pushValue(&$record, &$element){ // Get the employer name as entered in the text field $employerName = $element->getValue(); // Get the associated employer id $employerRecord = df_get_record('employers', array('employerName'=>$employerName)); // If employer doesn't exist yet, we create a new one if ( !$employerRecord){ $employerRecord = new Dataface_Record('employers', array()); $employerRecord->setValue('employerName', $employerName); $employerRecord->save(); }
// Return the employer ID for this employer return $employerRecord->val('employerID'); }
function employerid__pullValue(&$record, &$element){ // we'll be a bit tricky here and use valuelists on this // field. When using valuelists, the display() method will // display the display value of the field instead of the // id. Since we want to return the display value, // all we need to do is...
return $record->display('employerID'); }
And in our fields.ini file we'd have something like: - Code: Select all
[employerID] vocabulary=employers widget:type=autocomplete
And in our valuelists.ini we'd have something like: - Code: Select all
[employers] __sql__ = "select employerID, employerName from employers"
or something along those lines.
-Steve
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
by tnorbut13 » Tue Apr 28, 2009 12:47 pm
Steve,
Thanks for the answer. Where would I put this new function? In a separate action or in an existing action?
-
tnorbut13
-
- Posts: 36
- Joined: Thu Apr 23, 2009 7:46 am
- Location: Chicago, IL
by shannah » Tue Apr 28, 2009 12:59 pm
These methods go in the delegate class for the table in question.
Check out the section of the getting started tutorial on delegate classes for more info.
-
shannah
-
- Posts: 4457
- Joined: Wed Dec 31, 1969 5:00 pm
Return to Xataface Users
Who is online
Users browsing this forum: No registered users and 0 guests
|