textfield

Flutter: How to supply an initial value to a TextFormField

If you need to supply an initial value to a Flutter TextFormField (and possibly a TextField), the initialValue parameter may not do what you expect it to do. (More on this in the Discussion.) Instead, I just used this technique to populate the initial value for a TextFormField when using it with a TextEditingController:

A sample Scala/JavaFX application

As a brief note to self, here’s an example JavaFX application written in Scala:

object MainWindow {
    def main(args: Array[String]) {
        Application.launch(classOf[MainWindow], args: _*)
    }
}

class MainWindow extends Application  {
    override def start(stage: Stage) {
        val borderPane = new MainBorderPane
        val scene = new Scene(borderPane, 600, 400)
        scene.getStylesheets.add(getClass.getResource("pizza.css").toExternalForm)
        stage.setScene(scene)
        stage.setTitle("Al’s Pizza")
        stage.show
    }
}

Android source code to show a popup dialog with a text field

I am working on a way to rapidly mock up Android applications using Android Studio, i.e., to rapidly prototype Android applications on the fly, and little snippets of code help to make this happen. For instance, this snippet of code shows how to show a popup dialog to prompt a user to enter information into a text field:

How to convert a Sencha ExtJS textfield to uppercase on the textfield blur event

This brief Sencha tutorial shows how to convert the text in a Sencha ExtJS textfield to uppercase on the textfield blur event. I use this technique on the symbol field in a form where I let users enter stock symbols, such as “AAPL”, “GOOG”, etc.

First, the symbol field in my StockForm.js view component is defined like this:

Drupal form default input focus

Drupal form FAQ: How do I get default input focus on a Drupal form field (presumably a form textfield)?

There may be a better way to do this, but here's what I just did to get default input focus on a series of Drupal form 'add' and 'edit' pages. I just included the following Drupal form suffix definition on any form where I wanted to control the default input focus:

The Drupal form field required syntax

Drupal form fields FAQ: What is the syntax to make a Drupal form field (textfield, textarea, password field) required?

To make a Drupal form field required, just use the Drupal form #required attribute, as shown in this required textfield example:

$form['first_name'] = array(
  '#title' => t('First Name'),
  '#type' => 'textfield',
  '#required' => TRUE,
);

As you can see, to set a Drupal form field to be required, you just need to add the #required form attribute, and set it to TRUE.

 

Drupal form textfield help text (description) syntax

Drupal form textfield FAQ: How do I set the "help" text for a Drupal form textfield?

The help text that you normally see with a Drupal textfield comes from the Drupal form "#description" attribute. Here's a quick example:

Drupal form textfield default value syntax

Drupal form textfield FAQ: How do I set the default value for a textfield in a Drupal form?

Just use the Drupal form "#default_value" tag, like this:

$form['first_name'] = array(
  '#title' => t('First Name'),
  '#type' => 'textfield',
  '#default_value' => 'John',
);

Here's an example of setting the default value of a Drupal textfield to a variable instead of a static text string:

Drupal form textfield required syntax

Drupal form textfield FAQ: What is the syntax to make a Drupal textfield required?

Just use the Drupal form #required property, like this:

$form['first_name'] = array(
  '#title' => t('First Name'),
  '#type' => 'textfield',
  '#required' => TRUE,
);

In that example the Drupal form textfield is made required by setting the "#required" tag equal to TRUE.