CMB2 / CMB2

CMB2 is a developer's toolkit for building metaboxes, custom fields, and forms for WordPress that will blow your mind.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Feature Request - Field column classes

JiveDig opened this issue · comments

Human Made's fork does something similar but i don't like the approach as much.

I used before_row and after_row to wrap my field in <div class="prefix-one-half"> in order to add different amounts of columns via CSS. I used the CSS from Genesis/Bootstrap for the columns. It works and looks great BUT it adds a wrap around the cmb-row. That causes problems when i need to target all rows via CSS.

It would be great to have an attribute for:
columns -> 'one-half first' and columns -> 'one-half'

The same way Genesis does it. The one-half.first clears the float and removes the left margin.

This setting would add the classes right inside the cmb-row div.. for consistency.
The output would be:

<div class="cmb-row cmb-one-half cmb-first">

Columns would be all the bootstrap/G stuff... one-half one-third one-fourth, two-thirds, etc... Not much CSS involved, it's just getting the attribute/parameter setup.

This was one of the reasons I switched to Human Made's fork before CMB2 rolled around. Would love to see this implemented. I'd assume though that it would apply exclusively to "Grouped" fields since without a groups such columns could produce strange results.

That's a nice idea for a workaround though. Will be testing that out a bit.

There is a filter for the field row classes, cmb2_row_classes. I think that would probably be sufficient for adding the column classes for a proof of concept, right? I'd consider adding this feature, but we'd need to figure out which contexts it would make sense to apply the column styling. I don't think it would be a good fit for a user profile page, for instance. Bottom line, it's not as simple as it may seem, and would need some major testing.

Since CMB is so dev friendly... would it make more sense to just and a field attribute for class? Then we can add whatever class we want to whatever field we want. More flexible and less room for error?

Similar to what ACF just added to Pro.
screen shot 2015-02-09 at 10 36 49 am

Btw.. here's an example of what we are doing in our soon-to-be-released recipe plugin that uses CMB2. Without columns, the layout would get out of control.
screen shot 2015-02-09 at 10 34 19 am

I've added a row_classes parameter, and you can see it/use it in trunk. changelog

This is awesome! Extremely useful IMO. Thanks!

Nice. That will already be a big benefit, and I agree with @JiveDig, the whole tool is targeted toward developers, if we break stuff while building we'll figure it out, this addition just gives us more flexibility to build better. Thanks!

Great addition. Some field sets can just get too long....

If you guys can build a solid proof of concept for making this work w/ columns, then we can get closer to getting into core.

@DevinWalker if you're referring to the unwieldy nature of the metabox config arrays, one of the goals for a future update is to convert that array to using at least a few helper functions. No matter what though, config can get large/crazy depending on what you're trying to do.

@jtsternberg proof of concept more then my recipe plugin screenshot? I'm going to convert our row wraps to this method this week... but it will look the same

@JiveDig yah, proof of concept like make a library (something like https://github.com/WebDevStudios/cmb2-attached-posts) that allows others to do the same, then test it in other scenarios like user profile pages, admin settings pages, front-end forms, etc. Make sense? Or a pull request, but that's harder to get a lot of people using/testing. Basically a workflow similar to WordPress' features-as-plugins concept.

@jtsternberg no I'm referring to the ability to add columns like the screenshot. I'm fine with the long arrays in the code.

@DevinWalker ah, makes sense! I bet you and @JiveDig could come up w/ a killer proof of concept. ;)

Okay, just to clarify... the row_classes parameter making it into core, right? Just nothing to do with columns at the moment?

@JiveDig that's correct. It's in core now (in trunk) and will be rolled into the next release.

I've made a CMB2 plugin for that:
https://github.com/origgami/CMB2-grid

CMB2 Grid - A grid system for Wordpress CMB2 library that allows the creation of columns for a better layout in the admin

I hope you guys enjoy it and give me a feedback

Pretty cool work @Pablo-Pacheco - combine that with the ability to add tabs then it's really taking it to the next level.

Thank you :)

It's a good idea

I happen to come across this thread. What about integrating CMB2 grid directly into the CMB2 core?
(Since this thread is a bit old right now perhaps CMB2 already has something very similar integrated.)

I think this one is a must!

I am using cmb2-grid but integrated will be the best solution!

+1 in seeing the cmb2-grid integrated!

Is it integrated yet?