Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,6 @@ If the field is visible it sets the initial value otherwise it removes the value

#### @DEFAULT-FROM-PREVIOUS-EVENT
Sets a field's default value based on its own value in a previous event. To map the default value from another field, you may specify the source as a parameter to the action tag, e.g `@DEFAULT-FROM-PREVIOUS-EVENT="source_field"`.

#### @FIELD-NOTE-DISPLAY
Provides alternative display modes for field notes. If the input is "hover", i.e. `@FIELD-NOTE-DISPLAY="hover"`, field notes will be only displayed on field hover.
43 changes: 43 additions & 0 deletions includes/field_note_display.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
/**
* @file
* Provides Field Note Display feature.
*/

require_once 'helper.php';

/**
* Handles @FIELD-NOTE-DISPLAY action tag.
*/
function auto_populate_fields_field_note_display() {
global $Proj;
$returnVal = array();

foreach (auto_populate_fields_get_fields_names() as $field_name) {
$field_info = $Proj->metadata[$field_name];
if (!$field_notes = $field_info['element_note']) {
continue;
}

if (!$display_mode = Form::getValueInQuotesActionTag($field_info['misc'], '@FIELD-NOTE-DISPLAY')) {
continue;
}

if (!isset($returnVal[$display_mode])) {
$returnVal[$display_mode] = array();
}

switch ($display_mode) {
case 'hover':
$returnVal[$display_mode]['#' . $field_name . '-tr'] = $field_notes;
break;
}

}

if (empty($returnVal)) {
return false;
}

return $returnVal;
}
27 changes: 19 additions & 8 deletions includes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ function auto_populate_fields_get_available_features() {
if (PAGE == 'surveys/index.php' && !(isset($_GET['s']) && defined('NOAUTH'))) {
return $features;
}

if (auto_populate_fields_form_has_data()) {
return $features;
}

$features[] = 'default_from_field';
$features[] = 'default_when_visible';
$features[] = 'field_note_display';

if (PAGE == 'DataEntry/index.php') {
$features[] = 'default_from_previous_event';
Expand Down Expand Up @@ -97,12 +98,7 @@ function auto_populate_fields_action_tag_semaphore($misc, $action_tag, $return_v
}

// Establishing a priority queue for action tags.
$priority_queue = array(
'@DEFAULT',
'@DEFAULT-WHEN-VISIBLE',
'@DEFAULT-FROM-FIELD',
'@DEFAULT-FROM-PREVIOUS-EVENT',
);
$priority_queue = auto_populate_fields_get_priority_queue();

foreach ($priority_queue as $item) {
$regex = '/(' . $item . ')($|[^(\-)])/';
Expand All @@ -122,10 +118,25 @@ function auto_populate_fields_action_tag_semaphore($misc, $action_tag, $return_v
return false;
}

/**
* Gets the action tags that can conflict with each other.
*
* @return array
* List of action tags in priority order.
*/
function auto_populate_fields_get_priority_queue() {
return array(
'@DEFAULT',
'@DEFAULT-ON-VISIBLE',
'@DEFAULT-FROM-FIELD',
'@DEFAULT-FROM-PREVIOUS-EVENT',
);
}

/**
* Gets fields names for the current event.
*
* @return arrray
* @return array
* An array of fields names.
*/
function auto_populate_fields_get_fields_names() {
Expand Down
6 changes: 6 additions & 0 deletions js/field_note_display.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$(document).ready(function() {
var settings = autoPopulateFields.field_note_display;
$.each(settings.hover, function (selector, field_notes) {
$(selector).prop('title', field_notes).find('.note').hide();
});
});
3 changes: 2 additions & 1 deletion js/helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ $(document).ready(function() {
var texts = {
'@DEFAULT-FROM-PREVIOUS-EVENT': 'Sets a field\'s default value based on its own value in a previous event. To map the default value from another field, you may specify the source as a parameter to the action tag, e.g @DEFAULT-FROM-PREVIOUS-EVENT="source_field".',
'@DEFAULT-WHEN-VISIBLE': 'If the field is visible it sets the initial value otherwise it removes the value. This is mainly useful in fields which are visible and hidden by branching logic, e.g. @DEFAULT-FROM-FIELD=\'10\'.',
'@DEFAULT-FROM-FIELD': 'Sets a field\'s default value from an existing field on the same form. This is useful when using hidden fields as source for visible fields, e.g. @DEFAULT-FROM-FIELD=\'hidden_first_name\'.'
'@DEFAULT-FROM-FIELD': 'Sets a field\'s default value from an existing field on the same form. This is useful when using hidden fields as source for visible fields, e.g. @DEFAULT-FROM-FIELD=\'hidden_first_name\'.',
'@FIELD-NOTE-DISPLAY': 'Provides alternative display modes for field notes. If the input is "hover", i.e. @FIELD-NOTE-DISPLAY="hover", field notes will be only displayed on field hover.'
};

$.each(texts, function(tag_name, descr) {
Expand Down