Jump to content

skipLabel question


KarlvonKarton
 Share

Recommended Posts

Could someone help me out a little?  Thank you!
Following code does not remove the label at all, but I can't seem to find the reason why.  (I have tried skipLabelBlank too, same result)

// create a checkbox
$field = $modules->get("InputfieldCheckbox");
$field->attr('id+name','test');
$field->label = '';
$field->skipLabel = Inputfield::skipLabelHeader;  // DOES NOTHING?
$form->add($field);

ps: I'm using PW 3.x

Link to comment
Share on other sites

The skipLabel option is about whether or not to render the header of the inputfield.

An example with InputfieldText:

$f = $modules->get('InputfieldText');
$f->name = 'text1';
$f->label = 'label';
$inputfields->add($f);

$f = $modules->get('InputfieldText');
$f->name = 'text2';
$f->label = 'label';
$f->skipLabel = Inputfield::skipLabelHeader;
$inputfields->add($f);

2018-04-18_124500.png.3672cae13736ff0ed78ff2a762179ecf.png

For InputfieldCheckbox, the header is already not rendered by default unless a description is defined for the inputfield. Instead, the label is rendered next to the checkbox itself. So setting skipLabelHeader or skipLabelBlank won't do anything because the header is already skipped.

If you do want a separate header label for InputfieldCheckbox you can use the "checkboxLabel" or "label2" properties (they both do effectively the same thing). When these properties are set the "label" is rendered in the header and the "checkboxLabel" or "label2" is rendered next to the checkbox:

$f = $modules->get('InputfieldCheckbox');
$f->name = 'checkbox1';
$f->label = 'label';
$inputfields->add($f);

$f = $modules->get('InputfieldCheckbox');
$f->name = 'checkbox2';
$f->label = 'label';
$f->checkboxLabel = 'checkboxLabel';
$inputfields->add($f);

2018-04-18_125336.png.110911564b2d7735ba8daa73f4cd3ce3.png

If your question is actually "is it possible to have a checkbox without any text next to it" I think the answer is no, not using the API options. You could try a str_replace() in a hook after InputfieldCheckbox::render, or use Javascript to remove the text.

Edit: another alternative for a checkbox without text next to it is to use a space character as the label:

$f = $modules->get('InputfieldCheckbox');
$f->name = 'checkbox1';
$f->label = ' ';
$inputfields->add($f);

 

  • Like 6
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...