-
Notifications
You must be signed in to change notification settings - Fork 23
Maybe the most important widget: the field
P4A_Field is a widget that allows users to input data. Every field has a type between:
- text: a single line data input
- date: a single line data input for dates, values are automatically formatted respecting your locale settings. This type features a nice date picker too.
- checkbox: the name is self-explanatory
- select: HTML combobox
- radio: a group of HTML radio buttons
- password: HTML input type="password"
- file: file upload with image/audio/video preview
- textarea: multiline data input
- rich_textarea: multiline data input featuring rich text editing controls
- multicheckbox: a group of checkboxes
- multiselect: HTML combobox featuring multiple selections
- hidden: HTML input type="hidden"
- label: converts the field to a simple data output, user can simply read the value
Use the setType method:
$field->setType("checkbox");
$this->build("p4a_field", "field")
->setType("text") // optional, text is the default type
->setWidth(200) // optional, fields already have a default width
->setLabel("Field") //optional, fields already have an auto-generated label
->setTooltip("Please enter you name here...") //optional, set a tooltip for your field
;
$frame->anchor($this->field);
to be written
You can use the setNewValue, getValue, getNewValue methods to get and set data to a field. Keep in mind that the getValue method gives you the current (or old) value and logical the getNewValue the newly changed data.
$this->build("p4a_field", "txt_myfield")
->setType("text") // optional, text is the default type
->setWidth(200) // optional, fields already have a default width
->setLabel("MyField"); //optional, fields already have an auto-generated label
$this->txt_myfield->setNewValue("this is my text");
$sMyNewVar = $this->txt_myfield->getNewValue();
$sMyOldVar = $this->txt_myfield->getValue();
//The same applies to DB fields
$this->fields->my_db_field->setNewValue("hey this is some new text in my field!");
You can use a array as source for the following field types:
- select
- radio
- multicheckbox
- multiselect
//build an array. You can also use an array with different value/key like array("id"=>0, "value"=>"item1")
$aTestArray[] = array("value"=>"item1");
$aTestArray[] = array("value"=>"item2");
$aTestArray[] = array("value"=>"item3");
$this->build("p4a_array_source", "db_array") //build the array source
->setPk("value")
->load($aTestArray);
$this->build("p4a_field", "msl_field") //build the select field
->setType("select")
->setLabel("Select")
->setSource($this->db_array) //setting the source for the field
->setSourceDescriptionField("value") //set the description field
->setSourceValueField("value"); //set the value field
$this->display("main", $this->msl_field); //display the field
You can add a simple input mask for alphanumeric characters like this:
$this->build("p4a_field", "txt_field")
->setLabel("Customer Code")
->setInputMask("aaa-99999/a");
$this->display("main", $this->txt_field);
User get this on his field -__/_ and can enter only a-z, A-Z and 0-9
You can add validation to you fields with the addValidator method. P4A implements different validators from the Zend framework. To see a list of all available validators take a look at the code-reference->p4a_validate.
$this->fields->my_db_field->addValidator(new P4A_Validate_Between(0,9)); //check if value is between 0 and 9
The validation will take place when trying to save the record. When a value is not valid, a red canvas will been drawn around the input field.
You can easly disable or enable a field for editing like this:
$this->my_field->disable();
$this->my_field->enable();
You can limit the amount of characters for a text field like this:
$this->my_field->setProperty("maxlength", "10");
General:
Documentation:
Theme customizations:
Contribs: