<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: field code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Fri, 16 May 2008 15:18:53 GMT</pubDate>
    <description>DZone Snippets: field code</description>
    <item>
      <title>PHP: Create a SELECT input field</title>
      <link>http://snippets.dzone.com/posts/show/4555</link>
      <description>Creates a SELECT input field with an optional parameter to preselect an item&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;function selectfield($optionsarray, $selected = "") {&lt;br /&gt;  $returnval = "";&lt;br /&gt;  foreach ($optionsarray as $field=&gt;$value) {&lt;br /&gt;    if ($field == $selected) {&lt;br /&gt;      $returnval .= "&lt;option selected value='" . $field . "'&gt;" . $value . "&lt;/option&gt;\n";&lt;br /&gt;    } else {&lt;br /&gt;      $returnval .= "&lt;option value='" . $field . "'&gt;" . $value . "&lt;/option&gt;\n";&lt;br /&gt;    }&lt;br /&gt;  }&lt;br /&gt;  &lt;br /&gt;  return $returnval;&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 19 Sep 2007 08:46:29 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/4555</guid>
      <author>cornerblue (CornerBLUE, Inc.)</author>
    </item>
    <item>
      <title>Actionscript _Text Class</title>
      <link>http://snippets.dzone.com/posts/show/3517</link>
      <description>Useful functions for adding dynamic text fields.  Don't forget, you have to add the font of choice into the main movie Library for this to work (Library Panel Menu &gt; New Font).  The name you give the font is the string that you pass to the getTextFormat function for the "font" parameter.  Setup your font styles with getTextFormat, setup your dynamic text box with getTextField, and then add text to the text box with appendTextField.&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;dynamic class _Text {&lt;br /&gt;	static function getTextFormat(font:String,size:Number,color:Number,leading:Number,url:String,target:String){&lt;br /&gt;		var fmt:TextFormat = new TextFormat();&lt;br /&gt;		fmt.font = font;&lt;br /&gt;		fmt.kerning = true;&lt;br /&gt;		fmt.leading = (leading != undefined &amp;&amp; leading != null) ? leading : 0;&lt;br /&gt;		fmt.bold = false;&lt;br /&gt;		fmt.size = (size != undefined &amp;&amp; size != null) ? size : 11;&lt;br /&gt;		fmt.color = (color != undefined &amp;&amp; color != null) ? color : 0x000000;&lt;br /&gt;&lt;br /&gt;		if (url != undefined &amp;&amp; url != null) {&lt;br /&gt;			fmt.url = url;&lt;br /&gt;			fmt.target = (target != undefined &amp;&amp; target != null) ? target : "_self";&lt;br /&gt;		}&lt;br /&gt;		return (fmt);&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	static function getTextField(targetMC,targetDepth,txtFieldName,x,y,w,h,txtObj){&lt;br /&gt;		var targetDepth = (targetDepth != undefined &amp;&amp; targetDepth != null) ? targetDepth : targetMC.getNextHighestDepth();&lt;br /&gt;		var txtfld = targetMC.createTextField(txtFieldName, targetDepth, x, y, w, h);&lt;br /&gt;		txtfld.antiAliasType = (txtObj.antiAliasType) ? txtObj.antiAliasType : "advanced";&lt;br /&gt;		txtfld.sharpness = (txtObj.sharpness) ? txtObj.sharpness : -60;&lt;br /&gt;		txtfld.thickness = (txtObj.thickness) ? txtObj.thickness : -100;&lt;br /&gt;		txtfld.embedFonts = (txtObj.embedFonts) ? txtObj.embedFonts : true;&lt;br /&gt;		txtfld.selectable = (txtObj.selectable) ? txtObj.selectable : false;&lt;br /&gt;		txtfld.html = (txtObj.html) ? txtObj.html : true;&lt;br /&gt;		txtfld.multiline = (txtObj.multiline) ? txtObj.multiline : true;&lt;br /&gt;		txtfld.autoSize = (txtObj.autoSize) ? txtObj.autoSize : "left";&lt;br /&gt;		&lt;br /&gt;		if (txtObj.htmlText) txtfld.htmlText = txtObj.htmlText;&lt;br /&gt;		if (txtObj.txtFormat) txtfld.setTextFormat(txtObj.txtFormat);&lt;br /&gt;		&lt;br /&gt;		if (txtObj.wordWrap == undefined || txtObj.wordWrap == null) txtfld._width = txtfld.textWidth + 10;&lt;br /&gt;		else txtfld.wordWrap = txtObj.wordWrap;&lt;br /&gt;		return txtfld;&lt;br /&gt;	}&lt;br /&gt;	&lt;br /&gt;	static function appendTextField(txtfld,txtfrmt,txt){&lt;br /&gt;		var beginIndex:Number = txtfld.htmlText.length;&lt;br /&gt;		txtfld.setNewTextFormat(txtfrmt);&lt;br /&gt;		txtfld.replaceText(beginIndex,beginIndex,txt);&lt;br /&gt;	}&lt;br /&gt;}&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 13 Feb 2007 20:17:40 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3517</guid>
      <author>bgidge (Bryan Gidge)</author>
    </item>
    <item>
      <title>Putting the errors in the right place</title>
      <link>http://snippets.dzone.com/posts/show/3403</link>
      <description>The idea is to display the error near the field instead of in global area at the top of the page.&lt;br /&gt;Simple&#8230; first go into your view and delete the&lt;br /&gt;&lt;code&gt;&lt;br /&gt;error_messages_for &#8216;object&#8217;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Then stick this in your application helper.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;# application_helper.rb&lt;br /&gt;def error_for(object, method = nil, options={})&lt;br /&gt;  if method&lt;br /&gt;    err = instance_variable_get("@#{object}").errors.on(method).to_sentence     rescue instance_variable_get("@#{object}").errors.on(method)&lt;br /&gt;  else&lt;br /&gt;     err = @errors["#{object}"] rescue nil&lt;br /&gt;  end&lt;br /&gt;  options.merge!(:class=&gt;&#8217;fieldWithErrors&#8217;,&lt;br /&gt;          :id=&gt;"#{[object,method].compact.join(&#8217;_')}-error",&lt;br /&gt;:style=&gt;(err ? #{options[:style]}":"#{options[:style]};display: none;")&lt;br /&gt;   )&lt;br /&gt; content_tag("p",err || "", options )     &lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Then in your form view, add an &#8216;error_for&#8217; call wherever you need one&#8230;&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;# _form.rhtml&lt;br /&gt;  &lt;p&gt;&lt;label for="code_project_name"&gt;Name&lt;/label&gt;&lt;br /&gt;  &lt;%= text_field &#8216;code_project&#8217;, &#8216;name&#8217;  %&gt;&lt;br /&gt;  &lt;%= error_for &#8216;code_project&#8217;, &#8216;name&#8217; %&gt;&lt;/p&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;If the model fails a validation test, then it will show the message right next to the field that caused the validation problem.&lt;br /&gt;Also note that if you define an instance variable called @errors containing a hash of field_names and messages, they will also be used. This is handy for those form fields that don&#8217;t correspond to a model attribute.</description>
      <pubDate>Thu, 01 Feb 2007 14:06:27 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3403</guid>
      <author>Mickael (Mickael)</author>
    </item>
    <item>
      <title>Java - PasswordField</title>
      <link>http://snippets.dzone.com/posts/show/3293</link>
      <description>&lt;code&gt;&lt;br /&gt;JPasswordField passField = new JPasswordField(10);&lt;br /&gt;passField.setEchoChar('*');&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Wed, 17 Jan 2007 02:20:15 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3293</guid>
      <author>whitetiger ()</author>
    </item>
    <item>
      <title>evaluate form fields with php</title>
      <link>http://snippets.dzone.com/posts/show/2610</link>
      <description>// contains all types of fields&lt;br /&gt;&lt;br /&gt;// of special interest are selection boxes. &lt;br /&gt;// They can return an array.&lt;br /&gt;// Here is a quick evaluation with implode().&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;!-- Formular auswerten (evaluate form)&lt;br /&gt;     ********************************** --&gt;&lt;br /&gt;&lt;br /&gt;&lt;?php&lt;br /&gt;$hidden_value_1 = $_POST['hval1'];&lt;br /&gt;$hidden_value_2 = $_POST['hval2'];&lt;br /&gt;&lt;br /&gt;$short_text	= $_POST['stext'];&lt;br /&gt;$password	= $_POST['pwd'];&lt;br /&gt;$long_text	= $_POST['ltext'];&lt;br /&gt;&lt;br /&gt;$selected_option = $_POST['optn'];&lt;br /&gt;$radio_selection = $_POST['radsel'];&lt;br /&gt;&lt;br /&gt;$check_selection = $_POST['checksel'];&lt;br /&gt;$check_text = implode(', ',$check_selection);&lt;br /&gt;?&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;html&gt;&lt;body&gt;&lt;br /&gt;&lt;h1&gt;Kurze Anzeige (show values)&lt;/h1&gt;&lt;br /&gt;Versteckte Werte: &lt;?=$hidden_value_1?&gt;, &lt;?=$hidden_value_2?&gt;&lt;br&gt;&lt;br /&gt;Kurzer Text und Passwort: &lt;?=$short_text?&gt;, &lt;span style="color: gray;"&gt;&lt;?=$password?&gt;&lt;/span&gt;&lt;br&gt;&lt;br /&gt;Langer Text:  &lt;?=$long_text?&gt;&lt;br&gt;&lt;br /&gt;Option: &lt;?=$selected_option?&gt;&lt;br&gt;&lt;br /&gt;Radio-Auswahl: &lt;?=$radio_selection?&gt;&lt;br&gt;&lt;br /&gt;CheckBox-Auswahl: &lt;?=$check_text?&gt;&lt;br /&gt;&lt;br /&gt;&lt;h1&gt;Ein Formular (form)&lt;/h1&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- Das Beispielformular (form example)&lt;br /&gt;     ********************************** --&gt;&lt;br /&gt;&lt;form action="form.php" method="post"&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- versteckte Elemente (hidden elements) --&gt;&lt;br /&gt;&lt;input type="hidden" name="hval1" value="Der erste versteckte Wert"&gt;&lt;br /&gt;&lt;input type="hidden" name="hval2" value="Der zweite versteckte Wert"&gt;&lt;br /&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- einzeiliges Eingabefeld und Passwortfeld (text fields) --&gt;&lt;br /&gt;Kurzer Text und Passwort &lt;br&gt;&lt;br /&gt;&lt;input type="text" size="32" maxlength="64" name="stext" value="Kurze Textvorbelegung"&gt;&lt;br /&gt;&lt;input type="password" size="16" maxlength="16" name="pwd" value="geheim"&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- mehrzeiliges Eingabefeld (text area) --&gt;&lt;br /&gt;Langer Text &lt;br&gt;&lt;br /&gt;&lt;textarea cols="128" rows="4" name="ltext"&gt;&lt;br /&gt;Optionale Textvorbelegung (optional text presetting): kann bei&lt;br /&gt;mehrzeiligen Textfeldern lang sein,da gen&#252;gend Platz vorhanden ist.&lt;br /&gt;&lt;/textarea&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- Auswahlliste mit Vorauswahl (selection list) --&gt;&lt;br /&gt;Option &lt;br&gt; &lt;select name="optn"&gt;&lt;br /&gt;&lt;option selected&gt;Die Erste Option&lt;/option&gt;&lt;br /&gt;&lt;option&gt;Die zweite Option&lt;/option&gt;&lt;br /&gt;&lt;option&gt;Die dritte Option&lt;/option&gt;&lt;br /&gt;&lt;/select&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- Radio-Buttons mit Vorauswahl (radio buttons) --&gt;&lt;br /&gt;Radio-Auswahl &lt;br&gt;&lt;br /&gt;&lt;input type="radio" name="radsel" value="first"&gt;Die erste Radiowahl&lt;br&gt;&lt;br /&gt;&lt;input type="radio" name="radsel" value="seccond"&gt;Die zweite Radiowahl&lt;br&gt;&lt;br /&gt;&lt;input type="radio" name="radsel" value="third" checked&gt; Die dritte Radiowahl&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;CheckBox-Auswahl &lt;br&gt;&lt;br /&gt;&lt;input type="checkbox" name="checksel[]" value="chk1" checked&gt;Die erste Checkwahl&lt;br&gt;&lt;br /&gt;&lt;input type="checkbox" name="checksel[]" value="chk2" checked&gt;Die zweite Checkwahl&lt;br&gt;&lt;br /&gt;&lt;input type="checkbox" name="checksel[]" value="chk3"&gt;Die dritte Checkwahl&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;br /&gt;&lt;!-- Buttons zum Absenden/ Abbrechen (buttons to submit/reset) --&gt;&lt;br /&gt;&lt;input type="submit" value="auswerten"&gt;&lt;br /&gt;&lt;input type="reset" value="zur&#252;cksetzen"&gt;&lt;br /&gt;&lt;br /&gt;&lt;/form&gt;&lt;br /&gt;&lt;/body&gt;&lt;/html&gt;&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Sun, 17 Sep 2006 16:24:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/2610</guid>
      <author>ovhaag (Oliver Haag)</author>
    </item>
    <item>
      <title>Use background color to show error fields instead of wrapping them in a div</title>
      <link>http://snippets.dzone.com/posts/show/1912</link>
      <description>Using the default rails field_error_proc may lead to some layout headaches--your form looks perfect until, uh-oh, someone entered an invalid email address and Rails adds a fieldWithError-styled div that wraps around the problem field.&lt;br /&gt;&lt;br /&gt;While this works in many cases, some pixel-perfect layouts may not be able to tolerate the 2-pixel padding around the text_field caused by the red border.  An alternative is to change the background color of the offending field.&lt;br /&gt;&lt;br /&gt;Include the following code in environment.rb (or use a "require" like I do):&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;ActionView::Base.field_error_proc = Proc.new do |html_tag, instance|&lt;br /&gt;  error_style = "background-color: #ffff80"&lt;br /&gt;  if html_tag =~ /&lt;(input|textarea|select)[^&gt;]+style=/&lt;br /&gt;    style_attribute = html_tag =~ /style=['"]/&lt;br /&gt;    html_tag.insert(style_attribute + 7, "#{error_style}; ")&lt;br /&gt;  elsif html_tag =~ /&lt;(input|textarea|select)/&lt;br /&gt;    first_whitespace = html_tag =~ /\s/&lt;br /&gt;    html_tag[first_whitespace] = " style='#{error_style}' "&lt;br /&gt;  end&lt;br /&gt;  html_tag&lt;br /&gt;end&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;See my blog.inquirylabs.com for more Rails stuff.</description>
      <pubDate>Thu, 13 Apr 2006 22:21:47 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/1912</guid>
      <author>canadaduane (Duane Johnson)</author>
    </item>
  </channel>
</rss>
