Modifying Checkbox Display Helper
Permalink
Okay, so the current default for displaying a checkbox input renders a div, a label, another div, another label, the checkbox input, and the checkbox description, as shown in my first two attachments. This apparently has been the practice in c5 for quite a long time, but really? How does this make any sense for standards coding and easy usability? It has a label above the box when it should go beside, and a random label element used as a wrapper and a random span used where the label should go. This appears on two main places I've seen so far, the register page, and the edit profile info page.
I want to change this to make it look and behave better, and also because I need to have the checkboxes in a structure to apply some custom form styling I have. I've found the two main areas that need to be overridden, but I don't know how to do it. They are
concrete/helpers/form.php
concrete/helpers/form/attribute.php
The display function in attribute.php seems to be what causes the bloat, but the "<span>Yes</span>" doesn't appear here, so I'm missing something. And if I change anything, it affects the display of other attributes like textbox. On this thread:http://www.concrete5.org/community/forums/customizing_c5/styling-a-...
JordanLev says to view the source of the rendered page and just copy that code to replace the foreach loop which I have done and it works great. But if I add a new attribute then I'd have to update everything manually on every page these attributes show up. At the bottom of the thread, this guy says he made two other methods for checkboxes and text areas while keeping the foreach loop which sounds exactly like what I want to do. I have no idea how though, like how to tell when a checkbox is being passed vs a textbox.
I want to change this to make it look and behave better, and also because I need to have the checkboxes in a
<p><input></input><label></label></p>
concrete/helpers/form.php
concrete/helpers/form/attribute.php
The display function in attribute.php seems to be what causes the bloat, but the "<span>Yes</span>" doesn't appear here, so I'm missing something. And if I change anything, it affects the display of other attributes like textbox. On this thread:http://www.concrete5.org/community/forums/customizing_c5/styling-a-...
JordanLev says to view the source of the rendered page and just copy that code to replace the foreach loop which I have done and it works great. But if I add a new attribute then I'd have to update everything manually on every page these attributes show up. At the bottom of the thread, this guy says he made two other methods for checkboxes and text areas while keeping the foreach loop which sounds exactly like what I want to do. I have no idea how though, like how to tell when a checkbox is being passed vs a textbox.
Yes! This is perfect. I guess I missed looking in the model folder. And it isn't really a checkbox helper, it was the attribute helper and I was looking at making a checkboxDisplay method specifically for rendering checkbox attributes. I'll give this a go, but I might opt for doing everything manually so I clean everything up.
The override isn't working, so just to clarify:
I took the changed code from concrete/core/models/attributes/types/boolean.php
And placed it in models/attributes/types/boolean/controller.php. Nothing changed though. I'm used to overridden files having the same file names, even with the 5.6 update, so I thought that overriding boolean.php with controller.php might be the problem so I renamed it but nothing happened with that either.
The override isn't working, so just to clarify:
I took the changed code from concrete/core/models/attributes/types/boolean.php
public function form() { if (is_object($this->attributeValue)) { $value = $this->getAttributeValue()->getValue(); $checked = $value == 1 ? true : false; } else { $this->load(); if ($this->akCheckedByDefault) { $checked = true; } } $cb = Loader::helper('form')->checkbox($this->field('value'), 1, $checked); print $cb; } public function composer() { $this->form();
Viewing 15 lines of 16 lines. View entire code block.
And placed it in models/attributes/types/boolean/controller.php. Nothing changed though. I'm used to overridden files having the same file names, even with the 5.6 update, so I thought that overriding boolean.php with controller.php might be the problem so I renamed it but nothing happened with that either.
And this new override system is really a pain in the butt. I have to go through and redo all of my overrides and a lot of the things aren't the same... I guess that's the nature of a system update
Any idea how to override the controller of a package's attribute type rather than a core attribute type? Tried duplicating it in this similar manner to the top level models folder but no luck.
UPDATE: never mind had a folder named wrong, works fine overriding package attribute types :)
UPDATE: never mind had a folder named wrong, works fine overriding package attribute types :)
Just want to pitch in on how much I agree with jordanlev on the clean markup in the core, it's truly hideous and have not really been resolved all the way into 5.6.3.3 , Not sure about 5.7 I hope it's better
Anywho, I think you're talking about the "boolean attribute", not the form checkbox helper? If you're using Concrete5.6 or later, it's much easier to override stuff in the core now. Create this new file on your server (you'll need to create the subdirectories it's in as well):
(note that this is all under your top-level "models" directory, *NOT* "/concrete/models/").
Then put this code in that new file:
Hope that helps.
-Jordan