dev-master
9999999-devCreates simple text input fields
The Requires
by Fabio Souto
html forms widgets fields
1.0.0
1.0.0.0Creates simple text input fields
The Requires
by Fabio Souto
html forms widgets fields
Wallogit.com
2017 © Pedro Peláez
Creates simple text input fields
This stands for HTML Text Input. It's a library that caters for generating "one-line" text fields through a standard API which provides utilities for data formatting, processing and much more., (*1)
This is the first concrete implementation of the HtWidget class. You can click here and read more about it in order to better understand the whole philosophy., (*2)
Run composer:, (*3)
composer require flsouto/httextin
By default, the textin widget is rendered in writable mode which will expect input from the user:, (*4)
<?php
use FlSouto\HtTextin;
require_once('vendor/autoload.php');
$field = new HtTextin('email');
$field->context(['email'=>'user@domain.com']);
echo $field;
Outputs:, (*5)
use FlSouto\HtTextin;
require_once('vendor/autoload.php');
$field = new HtTextin('email');
$field->readonly(true);
echo $field;
Outputs:, (*6)
To turn readonly off and go back to writable:, (*7)
use FlSouto\HtTextin;
$field = new HtTextin('email');
$field->readonly(true);
$field->readonly(false);
echo $field;
Outputs:, (*8)
$field = new HtTextin('email'); $field->size(40); echo $field;
Outputs:, (*9)
$field = new HtTextin('email'); $field->size(40)->placeholder("eg: user@domain.com"); echo $field;
Outputs:, (*10)
The fromatter method allows you to format the value that is pulled from the context for showing on the input field:, (*11)
$field = new HtTextin('price'); $field->formatter(function($value){ return '$'.number_format((float)$value, 2, '.',','); }); $field->context(['price'=>30.9]); echo $field;
Outputs:, (*12)
The filters method returns an object which allows you to add filters for processing incoming data.
While formatter will be applied only when the widget is rendered, filters are always applied, às soon as the
the $field->value() method gets called:, (*13)
$field = new HtTextin('price'); $field->filters()->strip('$')->replace(',','.')->trim(); $field->context(['price'=>'$ 30,90']); echo $field->value();
Outputs:, (*14)
30.90
Validation constraints are added through the same filters api:, (*15)
$field = new HtTextin('amount'); $field->filters()->maxval(10, "Cannot exceed 10."); $field->context(['amount'=>15]); $field->error(true); // activates error reporting on the UI echo $field;
Outputs:, (*16)
Cannot exceed 10.
Notice: For more information about the filters api, please referer to this documentation, (*17)
Creates simple text input fields
html forms widgets fields
Creates simple text input fields
html forms widgets fields