phpMv -UI toolkit 2.4.12
jQuery, jQuery UI, Twitter Bootstrap and Semantic-UI library for php & php MVC Frameworks
Loading...
Searching...
No Matches
HtmlFormInput.php
Go to the documentation of this file.
1<?php
3
6
8
9 const TOGGLE_CLICK = 0;
10
12
13 const TOGGLE_INTERVAL = 2;
14
15 public function __construct($identifier, $label = NULL, $type = "text", $value = NULL, $placeholder = NULL) {
16 if (! isset($placeholder) && $type === "text")
17 $placeholder = $label;
18 parent::__construct("field-" . $identifier, new HtmlInput($identifier, $type, $value, $placeholder), $label);
19 $this->_identifier = $identifier;
20 }
21
22 public function getDataField() {
23 $field = $this->getField();
24 if ($field instanceof HtmlInput)
25 $field = $field->getDataField();
26 return $field;
27 }
28
34 public function asPassword($keyIcon = 'key') {
35 $this->setInputType('password');
36 if ($keyIcon != '') {
37 $this->addIcon($keyIcon);
38 }
39 }
40
51 public function addTogglePasswordAction($buttonIcon = 'eye', $keyIcon = 'key', $slashIcon = 'slash', $type = 0) {
52 $this->asPassword($keyIcon);
53 $action = $this->addAction('see');
54 $action->asIcon($buttonIcon);
55 switch ($type) {
57 $action->onClick('let th=$(this);' . $this->getJsToggle($slashIcon, '(_,attr)=>(attr=="text")?"password":"text"', 'toggle'));
58 break;
60 $action->onClick('');
61 $action->addEvent('mousedown', 'let th=$(this);' . $this->getJsToggle($slashIcon, '"text"', 'add'));
62 $action->addEvent('mouseup', 'let th=$(this);' . $this->getJsToggle($slashIcon, '"password"', 'remove'));
63 $action->addEvent('mouseout', 'let th=$(this);' . $this->getJsToggle($slashIcon, '"password"', 'remove'));
64 break;
66 $action->onClick('let th=$(this);' . $this->getJsToggle($slashIcon, '"text"', 'add') . 'setTimeout(function(){ ' . $this->getJsToggle($slashIcon, '"password"', 'remove') . ' }, 5000);');
67 break;
68 }
69 return $action;
70 }
71
72 private function getJsToggle($slashIcon, $type, $actionClass) {
73 return 'th.find(".icon").' . $actionClass . 'Class("' . $slashIcon . '");th.closest(".field").find("input").attr("type",' . $type . ');';
74 }
75}
addIcon($icon, $direction=Direction::LEFT)
__construct($identifier, $label=NULL, $type="text", $value=NULL, $placeholder=NULL)
asPassword($keyIcon='key')
Changes the input type to password and adds an icon.
getJsToggle($slashIcon, $type, $actionClass)
addTogglePasswordAction($buttonIcon='eye', $keyIcon='key', $slashIcon='slash', $type=0)
Adds an action to show/hide the password.
addAction($action, $direction=Direction::RIGHT, $icon=NULL, $labeled=false)