22 foreach( array_keys($this->options) as $k )
24 $o = $this->options[$k];
27 foreach( $o->options as $oo )
29 $oo->SetControl($this);
39 elseif ( is_array($o) )
49 $oo->SetControl($this);
75 private $allowNullValue =
true;
84 if ( is_array($_options) )
94 $options = array(
'' => _M(
'--Select--') );
100 $this->autoPostBack =
false;
106 foreach ( array_keys($this->options) as $k )
108 $o = $this->options[$k];
114 if ( $this->showValues )
124 else if ( trim(
$value) == trim($k) )
126 if ( $this->showValues )
128 $r = $k .
' - ' . $o;
142 $this->options[$option] =
$value;
152 $this->autoPostBack = $isAuto;
160 $this->allowNullValue = $allowNullValue;
168 return $this->allowNullValue;
175 if ( $this->event || $this->autoPostBack )
177 $this->AddAttribute(
'onChange',
" _doPostBack('{$this->event}','');" .
"document.{$this->page->name}.submit();");
180 if ( $this->GetClass() ==
'' )
182 $this->SetClass(
'm-combo form-control form-select');
185 if ( !$this->allowNullValue )
187 unset($this->options[
'']);
190 if ( $this->readonly )
192 $hidden = $this->GetRender(
'inputhidden');
193 $this->SetClass(
'm-readonly');
194 $this->AddAttribute(
'readonly');
195 $this->SetValue($this->
GetOption($this->GetValue()));
196 $this->size = $this->cols ? $this->cols : strlen(trim($this->
getValue())) + 10;
199 $this->inner = $this->GenerateLabel() . $this->GetRender(
'inputtext') . $hidden;
204 if ( $this->size !=
'' )
206 $this->AddAttribute(
'size', $this->size);
208 $this->inner = $this->GenerateLabel() . $this->GetRender(
'select');
230 $this->value = $values;
235 return (strpos($this->name,
'[]') !==
false ? $this->name : $this->name.
'[]');
245 if ( $this->value && !is_array($this->value) )
247 echo $this->painter->div(
new Div(
'', _M(
'Values must be a single-dimensional array'),
'alert'));
250 if ( !is_array($this->options) )
252 echo $this->painter->div(
new Div(
'', _M(
'Options must be a single or multi-dimensional array'),
'alert'));
256 $this->AddAttribute(
'multiple',
'');
257 $this->AddAttribute(
'size', $this->size);
259 if ( $this->GetClass() ==
'' )
261 $this->SetClass(
'm-combo m-multi-select');
264 $this->inner = $this->GenerateLabel() . $this->GetRender(
'select');
276 if (is_array($this->options)) {
277 reset($this->options);
278 $o = current($this->options);
285 if ( $this->readonly )
287 $this->SetClass(
'm-readonly form-control form-select');
288 $this->AddAttribute(
'readonly');
289 $this->SetValue($this->
GetOption($this->GetValue()));
290 $this->inner = $this->GenerateLabel() . $this->GetRender(
'inputtext');
294 if ( $this->autoPostBack )
296 $this->AddAttribute(
'onchange',
"showLoading();" .
297 "$('#m-loading-message-bg,#m-loading-message').unbind('click');" .
298 "$('#m-loading-message-bg,#m-loading-message').prop('onclick',null);".
299 "_doPostBack('{$this->event}','');".
300 "document.{$this->page->name}.submit();"
304 $text =
new MTextField($this->name,$this->value,
'',$this->size);
305 $text->SetAttributes($this->Attributes());
306 $text->AddAttribute(
'onChange',
"ComboBox_onTextChange('{$this->label}', this.form.elements['{$this->name}'],this.form.elements['{$this->name}_sel']);" . ( $this->autoPostBack ?
" _doPostBack('{$this->event}',''); document.{$this->page->name}.submit();" :
'' ));
309 $select =
new MSelection(
"{$this->name}_sel",$this->value,
'',$this->options);
310 $select->SetAttributes($this->Attributes());
311 $select->SetClass(
'm-combo m-combobox form-control form-select');
312 $select->AddAttribute(
'onChange',
"ComboBox_onSelectionChange('{$this->label}', this.form.elements['{$this->name}_sel'], this.form.elements['{$this->name}']);" . ( $this->autoPostBack ?
" _doPostBack('{$this->event}',''); document.{$this->page->name}.submit();" :
'' ));
313 $select->AddAttribute(
'onClick',
"ComboBox_onSelectionChange('{$this->label}', this.form.elements['{$this->name}_sel'], this.form.elements['{$this->name}'])");
314 $select->addStyle(
'width',
'70%');
318 $container =
new MHContainer(
"{$this->name}_hc", array($this->GenerateLabel(), $text, $select));
319 $container->addAttribute(
'style',
'min-width:500px');
321 $this->inner = $container->generate();
330 public function __construct(
$name = NULL, $label =
' ', $itensMenu = array(), $image = NULL )
332 parent::__construct(
$name );
338 $buttonInner =
new MButton(
'btnDropwon' .
$name, $label,
'NONE', $image);
339 $buttonInner->setClass(
'dropdown-toggle');
340 $buttonInner->addAttribute(
'data-toggle',
'dropdown');
341 $buttonInner->addAttribute(
'data-bs-toggle',
'dropdown');
342 $fieldsInner[] = $buttonInner;
351 $inner .=
'<ul class="dropdown-menu">';
353 foreach ($this->itensMenu as $itemMenu)
355 $inner .=
'<li>' . $itemMenu->generate() .
'</li>';
360 $class = $this->
getClass() .
' dropdown';
361 return '<div class="'.$class.
'">' .$inner.
'</div>';
366 return $this->itensMenu;
371 $this->itensMenu = $itensMenu;
377 private $limitSelect;
385 $this->limitSelect = $limitSelect;
395 if (!is_null($this->limitSelect))
397 $options[] =
"maximumSelectionLength: {$this->limitSelect}";
400 $optionsString = count(
$options) > 0 ?
'{' . implode(
', ',
$options) .
'}' :
'';
401 $this->manager->getPage()->onload(
"
402 $( document ).ready(function() {\$('#" . $this->name .
"').select2({$optionsString});});
405 return parent::GenerateInner();
410 return $this->limitSelect;
415 $this->limitSelect = $limitSelect;
__construct($name='', $value='', $label='', $options='', $showValues=false, $hint='', $size=6)
setClass( $cssClass, $add=true)
addStyleFile( $styleFile)
addAttribute( $name, $value='')
static getCurrentModule()
__construct($name='', $label='', $options='', $showValues=false, $hint='')
__construct($name='', $values=Array('1', '2', '3'), $label=' ', $options=Array('Option1', 'Option2', 'Option3'), $showValues=false, $hint='', $size='3')
SetOption($option, $value)
setIsRequired($isRequired)
SetAutoSubmit($isAuto=true)
__construct($name='', $value='', $label='', $options=array( 'Não', 'Sim'), $showValues=false, $hint='', $size='')
setAllowNullValue($allowNullValue=false)