checkboxes input-Feld
Das input-Feld vom Type "checkboxes" dient der Erfassung von mehreren Checkboxen in einer Gruppe in einem Formular.
/**
* Create a collection of Bootstrap checkboxes.
*
* @param string $name
* @param string $label
* @param array $choices
* @param array $checkedValues
* @param bool $inline
* @param array $options
* @return string
*/
public function checkboxes($name, $label = null, $choices = [], $checkedValues = [], $inline = false, array $options = []) {
Parameter für das "checkbox" Input-Feld
Name
Titel
Beschreibung
$name
Name des Input-Feldes. Dieser wird beim senden des Formulars in $_GET
übergeben.
$label
optional
Feldüberschrift für das Eingabefeld.
Wird kein $label
übergeben, so wird $name
als Label übernommen.
$choices
array mit Key=>Value Objekten, welche zur Auswahl stehen
$checkedValues
array mit Key-Einträgen, zur "Vorbelegung" der Werte
$inline
optional
true | false
bootstrap (V4 und höher) Option, zur Darstellung der Werte in horizontaler Ausrichtung
$options
optional
Array mit Optionen zu einem input-Feld. Hier sind grundsätzlich alle HTML-Attribute erlaubt.
Weiterhin können interne Optionen eingetragen werden, welche die Darstellung des Input-Feldes beeinflussen.
Optionale Parameter für das checkboxes Input-Feld
Name
Titel
Beschreibung
value_options
HTML-Attribut auf die Werte in $choices.
Kann genutzt werden, um z.B. ein class
-Attribut zu setzen, welches als selector
für javaScript / jQuery Funktionen dient.
cbgroup_options
optional
optionen, welche auf das gruppen <div> angewendet werden sollen Siehe Beispiel Option Required.
awesome-bootstrap-checkbox
Ab Version 2.x kann die formular-engine auch aufgehübschte Check- und Radio-Boxen darstellen, indem die CSS-Erweiterung awesome-bootstrap-checkbox implementiert wurde. http://flatlogic.github.io/awesome-bootstrap-checkbox/demo/1.0.0/
Beispiel
// eMail-Benachrichtigung
$FormHtml [] = $tb->checkboxes ( 'config[comments_email_notifications][]', af_tran ( 'eMail versenden, wenn' ), [
'new_comment' => af_tran ( 'jemand einen Kommentar schreibt' ),
'to_approve' => af_tran ( 'ein Kommentar auf Freischaltung wartet' )
], $this->_config ['comments_email_notifications'], false, [
'abc' => 'abc-checkbox-primary'
] );
// eMail-Benachrichtigung
$FormHtml [] = $tb->checkboxes ( 'config[comments_email_receiver][]', af_tran ( 'eMail versenden an' ), [
'author' => af_tran ( 'Author' ),
'admin' => af_tran ( 'Administrator' ),
'sender' => af_tran ( 'Verfasser des Kommentars' )
], $this->_config ['comments_email_receiver'], false, [
'abc' => [
'abc-checkbox-primary',
'abc-checkbox-success abc-checkbox-circle',
'abc-checkbox-warning'
]
] );

Je Wert kann eine eigene Klasse gesetzt werden. Falls nur ein Eintrag existiert, wird das Format auf alle Einträge angewendet.
CheckBox-Group: Option Required
In manchen Fällen kann es notwendig sein, dass beim Vorkommen mehrerer Checkboxes mindestens eine ausgewählt sein muss. Dies kann mit der Check-Box-Group = "required" erreicht werden:
Zur Prüfung wird ein jQuery-Skript ausgeführt
Beispiel
// eMail-Benachrichtigung
$FormHtml [] = $FrmObj->checkboxes ( 'clarification_to[]', af_tran ( 'An welche Abteilung soll die Rückfrage adressiert werden:' ), [
'AWETA' => af_tran ( 'AWETA' ),
'MS' => af_tran ( 'Market Support' )
], 2, false, [
'abc' => [
'abc-checkbox-primary',
'abc-checkbox-primary'
],
'cbgroup_options' => [
'class' => 'checkbox-group required'
],
'id' => 'btn_send_clarification_id'
] );
$FormHtml [] = '<div class="alert alert-danger mb-2" id="cb_send_clarivication_info_id" hidden="hidden">Bitte mindestens eine Abteilung auswählen!<br></div>';
$FormHtml [] = $FrmObj->button ( 'frm_save', af_tran ( 'Rückfrage zustellen' ), 'user/save_Encrease', 'submit', array (
'class' => 'btn btn-secondary ',
'iconclass' => 'fas fa-arrow-up',
'id' => 'btn_send_clarification_id',
'title' => af_tran ( 'Betriebsauftrag erhöhen' )
) );
// JavaScript, um Eingabefeld ein/auszublenden...
$js_script = '<script>' . "\n";
$js_script .= "\$('#btn_send_clarification_id').on(\"click\", function (e) {" . "\n";
$js_script .= " if( !\$('div.checkbox-group.required :checkbox:checked').length > 0) {" . "\n";
$js_script .= " e.preventDefault();" . "\n";
$js_script .= " \$(\"#cb_send_clarivication_info_id\").removeAttr(\"hidden\");" . "\n";
$js_script .= " }";
$js_script .= "});";
$js_script .= '</script>' . "\n";
$FormHtml [] = $js_script;

Last updated
Was this helpful?