Add input of type color to FormValidator - refs BT#12103

pull/2487/head
Angel Fernando Quiroz Campos 9 years ago
parent 5a4d41f5e2
commit f1111c1079
  1. 5
      app/Resources/public/css/base.css
  2. 52
      main/inc/lib/formvalidator/Element/Color.php

@ -6424,3 +6424,8 @@ ul#toolnavbox-two li a.btn{
width: 21.33333px;
height: 14.22222px;
}
input.form-control[type="color"] {
padding: 2px;
}

@ -0,0 +1,52 @@
<?php
/* For licensing terms, see /license.txt */
/**
* Input Color element
*
* Class Color
*/
class Color extends HTML_QuickForm_text
{
/**
* @param string $elementName
* @param string $elementLabel
* @param array $attributes
*/
public function __construct($elementName = null, $elementLabel = null, $attributes = null)
{
if (!isset($attributes['id'])) {
$attributes['id'] = $elementName;
}
$attributes['type'] = 'color';
$attributes['class'] = 'form-control';
$attributes['cols-size'] = isset($attributes['cols-size']) ? $attributes['cols-size'] : [2, 1, 9];
parent::__construct($elementName, $elementLabel, $attributes);
$this->_appendName = true;
$this->setType('color');
}
/**
* @return string
*/
public function toHtml()
{
return parent::toHtml() . <<<JS
<script>
$(document).on('ready', function () {
var txtColor = $('#{$this->getAttribute('id')}'),
lblColor = txtColor.parent().next();
lblColor.text(txtColor.val());
txtColor.on('change', function () {
lblColor.text(txtColor.val());
})
});
</script>
JS;
}
}
Loading…
Cancel
Save