HTML_INPUT improve and test
This commit is contained in:
parent
83670cecb8
commit
9c6aa2dee7
6 changed files with 145 additions and 33 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -47,3 +47,4 @@ local/*
|
|||
.idea/*
|
||||
include/tfpdf/font/unifont/*
|
||||
html/ads.html
|
||||
/nbproject/private/
|
||||
|
|
|
|||
|
|
@ -76,6 +76,7 @@ class HtmlInput
|
|||
var $id;
|
||||
var $style;
|
||||
var $css_size;
|
||||
var $placeholder; /*< $placeholder string in the INPUT Text */
|
||||
|
||||
function __construct($p_name="", $p_value="", $p_id="")
|
||||
{
|
||||
|
|
@ -100,9 +101,26 @@ class HtmlInput
|
|||
{
|
||||
$this->readOnly=$p_read;
|
||||
}
|
||||
/**
|
||||
* @return string HTML placeholder attribut
|
||||
*/
|
||||
public function get_placeholder()
|
||||
{
|
||||
return $this->placeholder;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief set HTML placeholder attribut
|
||||
* @param string $placeholder
|
||||
*/
|
||||
public function set_placeholder($placeholder)
|
||||
{
|
||||
$this->placeholder = $placeholder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief set the extra javascript property for the INPUT field
|
||||
* \brief add an HTML attribute for the INPUT field
|
||||
* \param $p_name name of the parameter
|
||||
* \param $p_value default value of this parameter
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -46,25 +46,9 @@ class IDate extends HtmlInput
|
|||
$this->extra="";
|
||||
$this->style=' class="input_text" ';
|
||||
$this->autofocus=false;
|
||||
$this->javascript='onchange="format_date(this)"';
|
||||
}
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function get_placeholder()
|
||||
{
|
||||
return $this->placeholder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $placeholder
|
||||
*/
|
||||
public function set_placeholder($placeholder)
|
||||
{
|
||||
$this->placeholder = $placeholder;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
@ -131,7 +115,8 @@ class IDate extends HtmlInput
|
|||
return $this->display();
|
||||
if ($this->id=="") $this->id=self::generate_id($this->name);
|
||||
$autofocus=($this->autofocus)?" autofocus ":"";
|
||||
$onchange='onchange="format_date(this)"';
|
||||
$strAttribute=$this->get_node_attribute();
|
||||
|
||||
$r=sprintf('
|
||||
<input type="text" name="%s" id="%s"
|
||||
class="input_text"
|
||||
|
|
@ -141,6 +126,7 @@ class IDate extends HtmlInput
|
|||
title="%s"
|
||||
pattern="[0-9]{1,2}\.[0-9]{1,2}\.[0-9]{4}"
|
||||
%s
|
||||
%s
|
||||
/>
|
||||
<span class="smallbutton icon"
|
||||
style="color:cornflowerblue"
|
||||
|
|
@ -149,7 +135,8 @@ class IDate extends HtmlInput
|
|||

|
||||
</span>
|
||||
',$this->name,$this->id,$this->value,$this->placeholder,$this->title,
|
||||
$onchange,
|
||||
$this->javascript,
|
||||
$strAttribute,
|
||||
$this->id
|
||||
);
|
||||
// @see calendar-setup.js
|
||||
|
|
|
|||
|
|
@ -35,8 +35,9 @@ class IHidden extends HtmlInput
|
|||
$this->name=($p_name==null)?$this->name:$p_name;
|
||||
$this->value=($p_value==null)?$this->value:$p_value;
|
||||
$this->id=($this->id=="")?$this->name:$this->id;
|
||||
|
||||
$r='<INPUT TYPE="HIDDEN" id="'.$this->id.'" name="'.$this->name.'" value="'.$this->value.'">';
|
||||
$strAttribute=$this->get_node_attribute();
|
||||
|
||||
$r='<INPUT TYPE="HIDDEN" id="'.$this->id.'" name="'.$this->name.'" value="'.$this->value.'" '.$strAttribute.' >';
|
||||
return $r;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,11 +28,11 @@
|
|||
*/
|
||||
class IText extends HtmlInput
|
||||
{
|
||||
var $placeholder;
|
||||
var $title;
|
||||
var $autofocus;
|
||||
var $css_size;
|
||||
|
||||
var $pattern; /*!< $pattern HTML pattern */
|
||||
var $maxlength; /*!< HTML maxlength */
|
||||
function __construct($name='',$value='',$p_id="")
|
||||
{
|
||||
parent::__construct($name,$value,$p_id);
|
||||
|
|
@ -43,6 +43,8 @@ class IText extends HtmlInput
|
|||
$this->autofocus=false;
|
||||
$this->require=false;
|
||||
$this->css_size="";
|
||||
$this->pattern="";
|
||||
$this->maxlength="";
|
||||
}
|
||||
/*!\brief show the html input of the widget*/
|
||||
public function input($p_name=null,$p_value=null)
|
||||
|
|
@ -60,11 +62,24 @@ class IText extends HtmlInput
|
|||
$t= 'title="'.$this->title.'" ';
|
||||
$autofocus=($this->autofocus)?" autofocus ":"";
|
||||
$require=($this->require)?"required":"";
|
||||
|
||||
// var $pattern regex to match the INPUT TEXT
|
||||
$pattern="";
|
||||
if ($this->pattern != "") {
|
||||
$pattern= sprintf( 'pattern="%s"',$this->pattern);
|
||||
}
|
||||
|
||||
// var maxlength HTML attribute
|
||||
$maxlength = "";
|
||||
if ($this->maxlength !="" ) {
|
||||
$maxlength=sprintf(' maxlength="%s" ',$this->maxlength);
|
||||
}
|
||||
|
||||
if ( ! isset ($this->css_size) || empty ($this->css_size))
|
||||
{
|
||||
|
||||
$r= sprintf('<INPUT TYPE="TEXT" %s id="%s" name="%s" value="%s" placeholder="%s" title="%s"
|
||||
Size="%s" %s %s %s %s %s>
|
||||
Size="%s" %s %s %s %s %s %s %s >
|
||||
',$this->style,
|
||||
$this->id,
|
||||
$this->name,
|
||||
|
|
@ -76,11 +91,13 @@ class IText extends HtmlInput
|
|||
$this->extra,
|
||||
$autofocus,
|
||||
$require,
|
||||
$strAttribute
|
||||
$strAttribute,
|
||||
$pattern,
|
||||
$maxlength
|
||||
);
|
||||
} else {
|
||||
$r= sprintf('<INPUT TYPE="TEXT" %s id="%s" name="%s" value="%s" placeholder="%s" title="%s"
|
||||
style="width:%s;" %s %s %s %s %s>
|
||||
style="width:%s;" %s %s %s %s %s %s %s>
|
||||
',$this->style,
|
||||
$this->id,
|
||||
$this->name,
|
||||
|
|
@ -92,7 +109,9 @@ class IText extends HtmlInput
|
|||
$this->extra,
|
||||
$autofocus,
|
||||
$require,
|
||||
$strAttribute
|
||||
$strAttribute,
|
||||
$pattern,
|
||||
$maxlength
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -108,6 +127,7 @@ class IText extends HtmlInput
|
|||
$t= ((isset($this->title)))?'title="'.$this->title.'" ':' ';
|
||||
|
||||
$extra=(isset($this->extra))?$this->extra:"";
|
||||
$strAttribute=$this->get_node_attribute();
|
||||
|
||||
$readonly=" readonly ";
|
||||
$this->value=htmlentities($this->value??"", ENT_COMPAT|ENT_QUOTES, "UTF-8");
|
||||
|
|
@ -117,12 +137,12 @@ class IText extends HtmlInput
|
|||
$r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
|
||||
$this->id.'"'.$t.
|
||||
'NAME="'.$this->name.'" VALUE="'.$this->value.'" '.
|
||||
'SIZE="'.$this->size.'" '.$this->javascript." $readonly $this->extra >";
|
||||
'SIZE="'.$this->size.'" '.$this->javascript." $readonly $this->extra $strAttribute>";
|
||||
} else {
|
||||
$r='<INPUT '.$this->style.' TYPE="TEXT" id="'.
|
||||
$this->id.'"'.$t.
|
||||
'NAME="'.$this->name.'" VALUE="'.$this->value.'" '.
|
||||
' style="width:'.$this->css_size.'" '.$this->javascript." $readonly $this->extra >";
|
||||
' style="width:'.$this->css_size.'" '.$this->javascript." $readonly $this->extra $strAttribute>";
|
||||
}
|
||||
|
||||
/* add tag for column if inside a table */
|
||||
|
|
|
|||
|
|
@ -175,7 +175,92 @@ $http=new HttpInput();
|
|||
echo $icard->input();
|
||||
echo $icard->search();
|
||||
?>
|
||||
|
||||
<div id="debug_box"></div>
|
||||
<h2>itext </h2>
|
||||
<h3>HTML Attribute</h3>
|
||||
<pre>
|
||||
$itext=new IText("itext_name");
|
||||
$itext->set_attribute("key1",1);
|
||||
$itext->set_attribute("data1","-data-");
|
||||
$itext->set_attribute("logx","data:logx");
|
||||
echo $itext->input();
|
||||
echo $itext->display();
|
||||
</pre>
|
||||
<?php
|
||||
$itext=new IText("itext_name");
|
||||
$itext->style=' class="input_text" ';
|
||||
$itext->set_attribute("key1",1);
|
||||
$itext->set_attribute("data1","-data-");
|
||||
$itext->set_attribute("logx","data:logx");
|
||||
echo $itext->input();
|
||||
echo $itext->display();
|
||||
?>
|
||||
<pre>
|
||||
<?= htmlspecialchars($itext->input());?>
|
||||
<?= htmlspecialchars($itext->display());?>
|
||||
</pre>
|
||||
<h3>Maxlenght = 15</h3>
|
||||
<?php
|
||||
$itext->maxlength=15;
|
||||
$itext->style=' class="input_text" ';
|
||||
|
||||
|
||||
echo $itext->input();
|
||||
echo $itext->display();
|
||||
?>
|
||||
<pre>
|
||||
<?= htmlspecialchars($itext->input());?>
|
||||
<?= htmlspecialchars($itext->display());?>
|
||||
</pre>
|
||||
<h3>placeholder</h3>
|
||||
<?php
|
||||
$itext->style=' class="input_text" ';
|
||||
$itext->placeholder="Donnez une information";
|
||||
echo $itext->input();
|
||||
echo $itext->display();
|
||||
?>
|
||||
<pre>
|
||||
$itext->placeholder="Donnez une information";
|
||||
<?= htmlspecialchars($itext->input());?>
|
||||
<?= htmlspecialchars($itext->display());?>
|
||||
</pre>
|
||||
<h3>require</h3>
|
||||
<?php
|
||||
$itext->style=' class="input_text" ';
|
||||
$itext->require=true;
|
||||
echo $itext->input();
|
||||
echo $itext->display();
|
||||
?>
|
||||
<pre>
|
||||
$itext->require=true;
|
||||
<?= htmlspecialchars($itext->input());?>
|
||||
<?= htmlspecialchars($itext->display());?>
|
||||
</pre>
|
||||
|
||||
<h3>pattern : uniquement des chiffres</h3>
|
||||
<form onsubmit="return false;">
|
||||
|
||||
<?php
|
||||
$itext->style=' class="input_text" ';
|
||||
$itext->pattern="[0-9]+";
|
||||
$itext->maxlength="4";
|
||||
$itext->placeholder="9999";
|
||||
$itext->title="code";
|
||||
echo $itext->input();
|
||||
echo $itext->display();
|
||||
echo HtmlInput::submit("valider","valider");
|
||||
?>
|
||||
<pre>
|
||||
$itext->pattern="[0-9]+";
|
||||
<?= htmlspecialchars($itext->input());?>
|
||||
<?= htmlspecialchars($itext->display());?>
|
||||
</pre>
|
||||
</form>
|
||||
<h2> IDATE</h2>
|
||||
<?php
|
||||
$date=new IDate('date_1',date("d.m.Y"));
|
||||
echo $date->input();
|
||||
echo htmlspecialchars($date->input());
|
||||
$date->id= uniqid();
|
||||
$date->javascript=sprintf('onchange = "console.debug(\'change date\');%s"',"format_date(this);");
|
||||
echo $date->input();
|
||||
?>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue