Tag Archive for field

Sort a multi-dimensional field

function orderBy($data, $field) {
	$code = "return strnatcmp($a['$field'], $b['$field']);";
	usort($data, create_function('$a,$b', $code));
	return $data;
}

source

OSG height field example

osg::Node* createHeightField(std::string heightFile, std::string texFile) {
 
    osg::Image* heightMap = osgDB::readImageFile(heightFile);
 
    osg::HeightField* heightField = new osg::HeightField();
    heightField->allocate(heightMap->s(), heightMap->t());
    heightField->setOrigin(osg::Vec3(-heightMap->s() / 2, -heightMap->t() / 2, 0));
    heightField->setXInterval(1.0f);
    heightField->setYInterval(1.0f);
    heightField->setSkirtHeight(1.0f);
 
    for (int r = 0; r < heightField->getNumRows(); r++) {
        for (int c = 0; c < heightField->getNumColumns(); c++) {
            heightField->setHeight(c, r, ((*heightMap->data(c, r)) / 255.0f) * 80.0f);
        }
    }
 
    osg::Geode* geode = new osg::Geode();
    geode->addDrawable(new osg::ShapeDrawable(heightField));
 
    osg::Texture2D* tex = new osg::Texture2D(osgDB::readImageFile(texFile));
    tex->setFilter(osg::Texture2D::MIN_FILTER,osg::Texture2D::LINEAR_MIPMAP_LINEAR);
    tex->setFilter(osg::Texture2D::MAG_FILTER,osg::Texture2D::LINEAR);
    tex->setWrap(osg::Texture::WRAP_S, osg::Texture::REPEAT);
    tex->setWrap(osg::Texture::WRAP_T, osg::Texture::REPEAT);
    geode->getOrCreateStateSet()->setTextureAttributeAndModes(0, tex);
 
    return geode;
}

source

Find table by column name

select * from user_tab_columns where column_name='column_name';

source

Drupal 6 CCK Get Allowed Fields List

function get_cck_text_field_allowed_values($field_name)
{
  $result = db_query("SELECT * FROM {node_field} WHERE field_name = '%s'", $field_name);
  if($row = db_fetch_array($result)){
    $field = unserialize($row['global_settings']);
    if($field['allowed_values']){
      
      $allowed_values = array();
      if ($field['allowed_values_php']) {
        ob_start();
        $result = eval($field['allowed_values_php']);
        if (is_array($result)) {
          $allowed_values = $result;
        }
        ob_end_clean();
      }
      if (!$allowed_values) {

        $list = explode("
", $field['allowed_values']);
        $list = array_map('trim', $list);
        $list = array_filter($list, 'strlen');
        foreach ($list as $opt) {
          // Sanitize the user input with a permissive filter.
          $opt = content_filter_xss($opt);
          list($key, $value) = explode('|', $opt);
          $allowed_values[$key] = (isset($value) && $value !=='') ? $value : $key;
        }
      }
      return $allowed_values;
    }
  }
  return NULL;
}

source

Render a CCK Image Field

function render_image_field($node,$name,$title=null,$divclass=null,$limit=0,$start=0) 
{


$field_name = 'field_'.$name;
$field = $node->{$field_name};

$limit = ($limit == 0) ? count($field): $limit;

for ($i=$start; $i < $limit; $i++) {
$output .= '<div class="field field-item'. ' '.$divclass .'"> ' ;
$output .= $field[$i]['view'];
$output .= '<span>' .$field[$i]['data']['description'] .'</span>';

$output .='</div>';
}
return ($output);
}

source

Custom Fields Template in WP – corresponding code snippets

// On code side:

Category:&nbsp;<?php
$group = get_post_meta($post->ID, 'Category');
foreach(($group) as $groups) {
echo $groups;
}
?>

Features:&nbsp;<?php
$group = get_post_meta($post->ID, 'Features');
foreach(($group) as $groups) {
echo $groups;
}
?>

<?php
$group = get_post_meta($post->ID, 'SiteLink');
foreach(($group) as $groups) {
echo $groups;
}
?>

<?php
$group = get_post_meta($post->ID, 'Description');
foreach(($group) as $groups) {
echo $groups;
}
?>


// On wp side:

[Category]
type = textfield

[Features]
type = textfield

[SiteLink]
type = textarea
rows = 2
cols = 60
tinyMCE = true

[Description]
type = textarea
rows = 8
cols = 60
tinyMCE = true

source

Toggle a money symbol to a form field on focus/blur – useful for cost data

jQuery.fn.moneyField = function(symbol) {
return this.each(function() {
$(this).focus(function(){
if(!$(this).val()) $(this).attr('value', symbol);
}).blur(function(){
if($(this).val() == symbol) {
$(this).attr('value', '');
} else {
s = $(this).val();
s = $.numAddCommas(s); // Add commas to long digit strings - you will need to get a function to do this (find one on snipplr)
$(this).attr('value', s);
var hascur = s.indexOf(symbol);
if(hascur) $(this).attr('value', symbol+s);
}
}).prev('label').click(function(){
return false;
});
});
}

$(function(){
$('input[name=money_field]').moneyField('£');
});

source

Adding a Focus class to Forms

$("input, textarea", $("form")).focus(function(){
$(this).addClass("focus");
$(this).parents(".form-field").addClass("cur");
});
$("input, textarea", $("form")).blur(function(){
$(this).removeClass("focus");
$(this).parents(".form-field").removeClass("cur");
});

source

inputLabel Plugin

/**
* jQuery Initial input value replacer
*
* Sets input value attribute to a starting value
* @author Marco "DWJ" Solazzi - <a href="mailto:hello@dwightjack.com">hello@dwightjack.com</a>
* @license  Dual licensed under the MIT (http://www.opensource.org/licenses/mit-license.php) and GPL (http://www.opensource.org/licenses/gpl-license.php) licenses.
* @copyright Copyright (c) 2008 Marco Solazzi
* @version 0.1
* @requires jQuery 1.2.x
*/
(function (jQuery) {
/**
* Setting input initialization
*
* @param {String|Object|Bool} text Initial value of the field. Can be either a string, a jQuery reference (example: $("#element")), or boolean false (default) to search for related label
* @param {Object} [opts] An object containing options:
* 							color (initial text color, default : "#666"),
* 							e (event which triggers initial text clearing, default: "focus"),
* 							force (execute this script even if input value is not empty, default: false)
* 							keep (if value of field is empty on blur, re-apply initial text, default: true)
*/
jQuery.fn.inputLabel = function(text,opts) {
o = jQuery.extend({ color: "#666", e:"focus", force : false, keep : true}, opts || {});
var clearInput = function (e) {
var target = jQuery(e.target);
var value = jQuery.trim(target.val());
if (e.type == e.data.obj.e && value == e.data.obj.innerText) {
jQuery(target).css("color", "").val("");
if (!e.data.obj.keep) {
jQuery(target).unbind(e.data.obj.e+" blur",clearInput);
}
} else if (e.type == "blur" && value == "" && e.data.obj.keep) {
jQuery(this).css("color", e.data.obj.color).val(e.data.obj.innerText);
}
};
return this.each(function () {
o.innerText = (text || false);
if (!o.innerText) {
var id = jQuery(this).attr("id");
o.innerText = jQuery(this).parents("form").find("label[for=" + id + "]").hide().text();
}
else
if (typeof o.innerText != "string") {
o.innerText = jQuery(o.innerText).text();
}
o.innerText = jQuery.trim(o.innerText);
if (o.force || jQuery(this).val() == "") {
jQuery(this).css("color", o.color).val(o.innerText);
}
jQuery(this).bind(o.e+" blur",{obj:o},clearInput);

});
};
})(jQuery);

source

JavaScript Form Field Validation

Example: property = oForm1.addProperty(
{ name:"businessName"
, friendlyName:"Business name"
, required:true
, minimumLength:2
, maximumLength:40
, trim:true
, onerror:myUserDefinedValue1
, onvalidate:myUserDefinedValue2 } );

source