{"action":"created","issue":{"url":"https://api.github.com/repos/thoughtbot/administrate/issues/351","labels_url":"https://api.github.com/repos/thoughtbot/administrate/issues/351/labels{/name}","comments_url":"https://api.github.com/repos/thoughtbot/administrate/issues/351/comments","events_url":"https://api.github.com/repos/thoughtbot/administrate/issues/351/events","html_url":"https://github.com/thoughtbot/administrate/issues/351","id":122773025,"number":351,"title":"Pass custom HTML classes into fields","user":{"login":"graysonwright","id":829576,"avatar_url":"https://avatars.githubusercontent.com/u/829576?v=3","gravatar_id":"","url":"https://api.github.com/users/graysonwright","html_url":"https://github.com/graysonwright","followers_url":"https://api.github.com/users/graysonwright/followers","following_url":"https://api.github.com/users/graysonwright/following{/other_user}","gists_url":"https://api.github.com/users/graysonwright/gists{/gist_id}","starred_url":"https://api.github.com/users/graysonwright/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/graysonwright/subscriptions","organizations_url":"https://api.github.com/users/graysonwright/orgs","repos_url":"https://api.github.com/users/graysonwright/repos","events_url":"https://api.github.com/users/graysonwright/events{/privacy}","received_events_url":"https://api.github.com/users/graysonwright/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-12-17T16:42:21Z","updated_at":"2015-12-18T11:23:48Z","closed_at":null,"body":"This conversation is carried over from #323. Here are the relevant comments from that issue:\r\n\r\n@michaelimstepf said:\r\n\r\n> Is there any way I can pass in an HTML class to a field? I saw in the Ruby docs that there's an html_class method but it doesn't accept any argument. I'm basically trying to add some custom styling (I have a verified checkbox/boolean for some attributes that I want to float left to the field it applies to).\r\n\r\n@graysonwright said:\r\n\r\n> @michaelimstepf The `html_class` method is part of the private API - it's not used for customizing the generated HTML.\r\n\r\n> The best way to do that right now would be to generate the view and override the HTML.\r\n\r\n> I think we could add better support for this by accepting a `html_class` option, like:\r\n\r\n> ```ruby\r\n> name: Field::String.with_options(html_class: \"username\")\r\n> ```\r\n\r\n> If we take that approach, the question comes up of how this is handled on the different pages. Would we apply the html class to the form as well as the table cell, or would we allow users to pass in different classes for each of the pages?\r\n\r\n> Another option would be to add another HTML class by default to all of the fields, with the format `.attribute-foobar`. That would let users select any field they want with selectors like `.cell-data.attribute-name`.\r\n\r\n> What are your thoughts on those options?\r\n\r\n@michaelimstepf said:\r\n\r\n> @graysonwright Thx. They syntax you posted looks very good to me.\r\n\r\n> Given that all three pages (index, show, edit) use different html attributes, I would just apply the same class to all of the three pages and then it's up to the user to limit the scope to a specific html element.\r\n\r\n> The other option you suggested (HTML class by default to all of the fields) would work but I think is inferior for the following reasons:\r\n\r\n> It's less DRY, in your CSS you'll maintain a list of attributes for a specific style as opposed to just using one single class:\r\n> ```css\r\n> .some-class {}\r\n> .attribute-name, .attribute-gender, .attribute-nationality {}\r\n> ```\r\n> And also, even though it's a class, it behaves more like an id, which is a bit confusing.\r\n\r\n> Then lastly, for me it would be very useful to have the class being applied to the wrapping element:\r\n> - table row for index\r\n> - div for form\r\n> - for show it's a bit tricky as there's no valid HTML element to wrap around unless you change the syntax: http://stackoverflow.com/a/10998064/1076279\r\n\r\n> The reason for this request is that for my use case I actually want to have certain related form fields floating next to each other. It's always easy to target a child within a class for those who want to only style an input or label tag but with pure CSS there's no sane way to target a parent element if the CSS is being applied to the input field for instance."},"comment":{"url":"https://api.github.com/repos/thoughtbot/administrate/issues/comments/165752294","html_url":"https://github.com/thoughtbot/administrate/issues/351#issuecomment-165752294","issue_url":"https://api.github.com/repos/thoughtbot/administrate/issues/351","id":165752294,"user":{"login":"zamith","id":166304,"avatar_url":"https://avatars.githubusercontent.com/u/166304?v=3","gravatar_id":"","url":"https://api.github.com/users/zamith","html_url":"https://github.com/zamith","followers_url":"https://api.github.com/users/zamith/followers","following_url":"https://api.github.com/users/zamith/following{/other_user}","gists_url":"https://api.github.com/users/zamith/gists{/gist_id}","starred_url":"https://api.github.com/users/zamith/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zamith/subscriptions","organizations_url":"https://api.github.com/users/zamith/orgs","repos_url":"https://api.github.com/users/zamith/repos","events_url":"https://api.github.com/users/zamith/events{/privacy}","received_events_url":"https://api.github.com/users/zamith/received_events","type":"User","site_admin":false},"created_at":"2015-12-18T11:23:48Z","updated_at":"2015-12-18T11:23:48Z","body":"@graysonwright Is this option passing preferable to overriding the view files?"}}