定制 flsouto/httextin 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

flsouto/httextin

Composer 安装命令:

composer require flsouto/httextin

包简介

Creates simple text input fields

README 文档

README

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.

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.

Installation

Run composer:

composer require flsouto/httextin

Usage

By default, the textin widget is rendered in writable mode which will expect input from the user:

<?php
use FlSouto\HtTextin;
require_once('vendor/autoload.php');

$field = new HtTextin('email');
$field->context(['email'=>'user@domain.com']);

echo $field;

Outputs:

<div class="widget 589f856da986a" style="display:block">
 <input name="email" value="user@domain.com" />
 <div style="color:yellow;background:red" class="error">
 </div>
</div>

Changing to Readonly Mode

use FlSouto\HtTextin;
require_once('vendor/autoload.php');

$field = new HtTextin('email');
$field->readonly(true);

echo $field;

Outputs:

<div class="widget 589f856dad400" style="display:block">
 <input name="email" value="" readonly="readonly" />
 <div style="color:yellow;background:red" class="error">
 </div>
</div>

To turn readonly off and go back to writable:

use FlSouto\HtTextin;

$field = new HtTextin('email');
$field->readonly(true);
$field->readonly(false);

echo $field;

Outputs:

<div class="widget 589f856dad92c" style="display:block">
 <input name="email" value="" />
 <div style="color:yellow;background:red" class="error">
 </div>
</div>

Set size attribute

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

echo $field;

Outputs:

<div class="widget 589f856dade03" style="display:block">
 <input name="email" size="40" value="" />
 <div style="color:yellow;background:red" class="error">
 </div>
</div>

Set placeholder attribute

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

echo $field;

Outputs:

<div class="widget 589f856dae2b0" style="display:block">
 <input name="email" size="40" value="" />
 <div style="color:yellow;background:red" class="error">
 </div>
</div>

Using a formatter

The fromatter method allows you to format the value that is pulled from the context for showing on the input field:

$field = new HtTextin('price');
$field->formatter(function($value){
	return '$'.number_format((float)$value, 2, '.',',');
});

$field->context(['price'=>30.9]);

echo $field;

Outputs:

<div class="widget 589f856dae783" style="display:block">
 <input name="price" value="$30.90" />
 <div style="color:yellow;background:red" class="error">
 </div>
</div>

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:

$field = new HtTextin('price');
$field->filters()->strip('$')->replace(',','.')->trim();
$field->context(['price'=>'$ 30,90']);

echo $field->value();

Outputs:

30.90

Validation

Validation constraints are added through the same filters api:

$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:

<div class="widget 589f856daf2f4" style="display:block">
 <input name="amount" value="" />
 <div style="color:yellow;background:red" class="error">
    Cannot exceed 10.
 </div>
</div>

Notice: For more information about the filters api, please referer to this documentation

统计信息

  • 总下载量: 80
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 2
  • 依赖项目数: 2
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-02-11

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固