KarlvonKarton Posted April 17, 2018 Share Posted April 17, 2018 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 More sharing options...
Robin S Posted April 18, 2018 Share Posted April 18, 2018 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); 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); 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); 6 Link to comment Share on other sites More sharing options...
KarlvonKarton Posted April 18, 2018 Author Share Posted April 18, 2018 Thank you, Robin S. Unfortunately when I do this: $field = $modules->get("InputfieldCheckbox"); $field->name = 'checkbox1'; $field->label = 'label'; $form->add($field); I always get this: PS: What I want is only the text next to the checkbox Link to comment Share on other sites More sharing options...
Robin S Posted April 18, 2018 Share Posted April 18, 2018 Not sure why that should be happening, but you can log/dump $label at different points in the code here to find out where the header label is coming from. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now