Dynamic activity description in a value-list.
Archived from the Xataface Users forum.
pdesbois — Wed Apr 29, 2009 5:26 am
Hello,
I’m a new Xataface user. Thanks to provide this very good tool
I made a table to store some activity (activity_list). In this table there is a name and a little description for each activity. In another table, I store the user weeklies. So, users can select an activity in a value-list. But in this value-list there are only activities name.
Is it possible to display the description of the activity selected when the user place the cursor into the value-list ?
Thanks and regards,
Patrice.
shannah — Wed Apr 29, 2009 7:36 am
This would require some custom javascript. Basically you would want to load all of the activities and their descriptions into a javascript array, then add an onchange handler to the select list to display the corresponding description some place on the screen.
pdesbois — Wed Apr 29, 2009 11:13 pm
Thanks a lot.
I will try this…
pdesbois — Tue May 05, 2009 8:50 am
Ok, I tried but I have a problem
How to load the activities and their descriptions into a javascript array (from MySql table) ? (I’m a new user, sorry…)
Regards,
Patrice.
shannah — Tue May 05, 2009 9:39 am
The easiest way to do this to use JSON to convert a PHP array into javascript. Then embed this code into your template.
e.g.
- Code: Select all
- `$res = mysql_query(“select id,name from foo order by name”, df_db());
if ( !$res ) trigger_error(mysql_error(df_db()), E_USER_ERROR);
$activities = array();
while ( $row = mysql_fetch_row($res) ){
$activities[$row[0]] = $row[1];
}$jsonActivities = json_encode($activities);
// $jsonActivities is a string representation of an javascript object.…`
This example merely shows how to form the javascript array. You will need to combine this with:
-
Insert javascript in an appropriate block or slot
-
Add onchange handler to your select list.
-steve
pdesbois — Wed May 06, 2009 12:22 am
Hi steve,
Thanks a lot, everything works correctly .
In the \tables\weekly.php file :
- Code: Select all
- `class tables_weekly {
…function block__before_items_widget() {
$app =& Dataface_Application::getInstance();
$auth =& Dataface_AuthenticationTool::getInstance();
$user =& $auth->getLoggedInUser();
$team = $user->val(‘TEAM’);
$sql = “select NAME,DESCRIPTION from activity_list where TEAM=’”.$team.”’”;
$res = mysql_query($sql);
if ( !$res ) trigger_error(mysql_error(df_db()), E_USER_ERROR);
$activities = array();
while ( $row = mysql_fetch_row($res) ){
$activities[$row[0]] = $row[1];
}
$jsonActivities = json_encode($activities);
// $jsonActivities is a string representation of an javascript object.
echo «<END
END;
}…
}`
In the tables\weekly_item\fields.ini :
- Code: Select all
[ACTIVITYREF] widget:label = "Activity" widget:type = select widget:atts:onMouseOver="displayPopup(this);" vocabulary = ...