2017 © Pedro Peláez
 

library httextin

Creates simple text input fields

image

flsouto/httextin

Creates simple text input fields

  • Saturday, February 11, 2017
  • by flsouto
  • Repository
  • 0 Watchers
  • 0 Stars
  • 32 Installations
  • PHP
  • 2 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

HtTextin

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)

Installation

Run composer:, (*3)

composer require flsouto/httextin

Usage

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)




Changing to Readonly Mode

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)




Set size attribute


$field = new HtTextin('email'); $field->size(40); echo $field;

Outputs:, (*9)




Set placeholder attribute


$field = new HtTextin('email'); $field->size(40)->placeholder("eg: user@domain.com"); echo $field;

Outputs:, (*10)




Using a formatter

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)




Using filters

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

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)

The Versions

11/02 2017

dev-master

9999999-dev

Creates simple text input fields

  Sources   Download

The Requires

 

by Fabio Souto

html forms widgets fields

11/02 2017

1.0.0

1.0.0.0

Creates simple text input fields

  Sources   Download

The Requires

 

by Fabio Souto

html forms widgets fields